我在一个活动中设置了 4 个 RadioButton。
我遇到了一个问题,当我单击“全部”单选按钮时,它会显示与“类别”单选按钮相对应的吐司。此外,当我单击“类别”单选按钮时,它会显示与“关于”单选按钮相对应的吐司。然后,当我单击“关于”单选按钮时,什么也没有显示。
我知道这与一些没有正确引导的事情有关,但似乎无法找出它是什么。
仅供参考:稍后我将使用这些 RadioButtons 打开活动,这就是为什么我没有完成 GetText 并且只使用了 1 个 OnCheckedChangeListener
任何帮助,将不胜感激!
主要活动:
public class MainActivity extends Activity {
GridView list;
LazyAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list = (GridView) findViewById(R.id.list);
adapter = new LazyAdapter(this, mStrings);
list.setAdapter(adapter);
RadioButton radioButton;
radioButton = (RadioButton) findViewById(R.id.btnAll);
radioButton.setOnCheckedChangeListener(btnAllOnCheckedChangeListener);
radioButton = (RadioButton) findViewById(R.id.btnAll);
radioButton
.setOnCheckedChangeListener(btnCategoriesOnCheckedChangeListener);
radioButton = (RadioButton) findViewById(R.id.btnCategories);
radioButton
.setOnCheckedChangeListener(btnPopularOnCheckedChangeListener);
radioButton = (RadioButton) findViewById(R.id.btnPopular);
radioButton.setOnCheckedChangeListener(btnAboutOnCheckedChangeListener);
radioButton = (RadioButton) findViewById(R.id.btnAbout);
}
private CompoundButton.OnCheckedChangeListener btnAllOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
Toast.makeText(getApplicationContext(), "Opened ALL tab", Toast.LENGTH_LONG).show();
}
}
};
private CompoundButton.OnCheckedChangeListener btnCategoriesOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
Toast.makeText(getApplicationContext(), "Opened CATEGORIES tab", Toast.LENGTH_LONG).show();
}
}
};
private CompoundButton.OnCheckedChangeListener btnPopularOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
Toast.makeText(getApplicationContext(), "Opened POPULAR tab", Toast.LENGTH_LONG).show();
}
}
};
private CompoundButton.OnCheckedChangeListener btnAboutOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
Toast.makeText(getApplicationContext(), "Opened ABOUT tab", Toast.LENGTH_LONG).show();
}
}
};