RadioGroup中onCheckedChanged功能将不火 [英] RadioGroup onCheckedChanged function won't fire
问题描述
我的应用程序跟踪餐厅服务器的转移销售,以帮助他们的预算。在显示过去变化的活动,我已经在ListView下创建一个RadioGroup中,使用户可以选择显示午餐,晚餐,或两者兼而有之。
My app keeps track of restaurant servers' shift sales to help them budget. In the activity that displays past shifts, I've created a RadioGroup under the ListView so the user can choose to display lunch, dinner, or both.
我在活动RadioGroup.onCheckedChangeListener实施,但onCheckedChanged不会被调用。我使用匿名内部类作为监听器,同样的结果也试过。
I've implemented in the activity RadioGroup.onCheckedChangeListener, but onCheckedChanged never gets called. I also tried using an anonymous inner class as listener, same result.
我试图从这个答案复制/修改code: http://stackoverflow.com/a/9595528 ...但是当我加入了 @覆盖
的回调函数,Eclipse编译器给了我一个错误(而不是警告),该方法必须重写超类,并快速修复是消除覆盖。
I tried to copy/modify code from this answer: http://stackoverflow.com/a/9595528 ...but when I added the @Override
to the callback function, the Eclipse compiler gave me an error (not warning) that the method must override a superclass, and the quick fix was to remove the override.
我是pretty确认签名的比赛,因为他们与Eclipse的自动完成制作并执行方法的设施。然后我跟着指示我的java编译器移动从1.5到1.6,并没有上述所列行为似乎变了。
I'm pretty sure the signatures are match, as they were made with Eclipse's autocomplete and implement methods facilities. I then followed instructions to move my java compiler from 1.5 to 1.6, and none of the above listed behavior seemed to change.
这里的code,我认为是相关的:
Here's the code I think is relevant:
public class DataActivity extends ListActivity implements OnCheckedChangeListener{
RadioButton rbBoth;
RadioButton rbDinnerOnly;
RadioButton rbLunchOnly;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.database);
// ...
final RadioGroup rgGroup = (RadioGroup)findViewById(R.id.DataRadioGroup);
rbBoth = (RadioButton)findViewById(R.id.RadioBoth);
rbDinnerOnly = (RadioButton)findViewById(R.id.RadioDinnerOnly);
rbLunchOnly = (RadioButton)findViewById(R.id.RadioLunchOnly);
rgGroup.setOnCheckedChangeListener(this);
populateAllShifts();
}
// ...
public void onCheckedChanged(RadioGroup group, int checkedId) {
rbLunchOnly.setText("Click!");
Toast.makeText(getApplicationContext(), "Lunch Only", Toast.LENGTH_LONG).show();
if(group.getCheckedRadioButtonId() == R.id.RadioBoth){
populateAllShifts();
return;
}
if(group.getCheckedRadioButtonId() == R.id.RadioLunchOnly){
populatLunchShifts();
return;
}
if(group.getCheckedRadioButtonId() == R.id.RadioDinnerOnly){
populateDinnerShifts();
return;
}
}
// ...
}
有在这一类自定义适配器一个ListView,但如果我的理解和我的XML是正确的,RadioGroup中应该是名单之外的:
There is a ListView in this class with a custom adapter, but if my understanding and my XML are correct, the RadioGroup should be outside of the list:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llDataLayout"
android:weightSum="5"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<ListView android:layout_weight="4"
android:layout_width="fill_parent"
android:id="@android:id/list"
android:layout_height="wrap_content">
</ListView>
<RadioGroup
android:layout_weight="1"
android:id="@+id/DataRadioGroup"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<RadioButton android:text="Lunch and Dinner"
android:textSize="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/RadioBoth"/>
<RadioButton android:text="Dinner Only"
android:textSize="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/RadioDinnerOnly"/>
<RadioButton android:text="Lunch Only"
android:textSize="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/RadioLunchOnly"/>
</RadioGroup>
</LinearLayout>
任何想法了吗?
推荐答案
发现问题,得到的答复是不是从我在我的问题给了信息可见。这个问题是多余的内容。
Found the problem, and the answer wasn't visible from the info I gave in my question. The problem was cruft.
这开始了我的第一个项目,并在笨拙的企图个月前解决数据库的问题,我已经extraneously以pretty中的onCreate大同小异code覆盖在onStart()和onRestart() ()。的onCreate随时间的变化,以及这些方法没有。一旦我删除它们时,code完美地工作。
This started as my first project, and in a ham-handed attempt to solve a database problem months ago, I had extraneously overridden onStart() and onRestart() with pretty much the same code in onCreate(). onCreate has changed over time, and those methods did not. Once I deleted them, the code worked perfectly.
我还没有显示在问题的方法。对不起!
I hadn't shown those methods in the question. Sorry!
谢谢大家对你的帮助!我现在应该怎么做?删除的问题?
Thanks everyone for your help! What should I do now? Delete the question?
这篇关于RadioGroup中onCheckedChanged功能将不火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!