從我的MainView
(ExpandableListView
)我得到RadioButton
定義child_row.xml
,我設置聽衆,但OnCheckChanged
不會被調用。如果我將RadioButton
移動到當前視圖,它會被調用。RadioButton OnCheckChanged不叫
我該如何解決這個問題?
我....
- mainListView.xml // expandableListView
- group_row.xml // TextView的
- child_row.xml //定製RADIOBUTTON
→
public class Main_ListView extends Activity implements OnCheckedChangeListener{
public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.mainListView);
ExpandableListView elv = (ExpandableListView) findViewById(R.id.expandableListView1);
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
getApplicationContext(),
createGroupList(), // Creating group List.
R.layout.group_row, // Group item layout XML.
new String[] { "Group Item" }, // the key of group item.
new int[] { R.id.row_name }, // ID of each group item.-Data under the key goes into this TextView.
createChildList(), // childData describes second-level entries.
R.layout.child_row, // Layout for sub-level entries(second level).
new String[] {"Sub Item"}, // Keys in childData maps to display.
new int[] { R.id.grp_child} // Data under the keys above go into these TextViews.
);
elv.setAdapter(expListAdapter); // setting the adapter in the list.
}catch(Exception e){
System.out.println("Errrr +++ " + e.getMessage());
}
final LayoutInflater factory = getLayoutInflater();
final View childview = factory.inflate(R.layout.child_row, null);
answersGroup = (SegmentedRadioGroup) childview.findViewById(R.id.answersGroup);
if(answersGroup != null)
answersGroup.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (group == answersGroup) {
if (checkedId == R.id.radio0) {
mToast.setText("One");
mToast.show();
} else if (checkedId == R.id.radio1) {
mToast.setText("Two");
mToast.show();
} else if (checkedId == R.id.radio2) {
mToast.setText("Three");
mToast.show();
}
}
}
它必須被調用,也許更改條件「if(group == answersGroup)」作爲測試如果2個對象在java中是完全相同的方法 – Benoit 2013-04-23 20:10:58
當我從不同的佈局獲取ID時缺少某些東西 - 導致它不會調用該方法。就像我說的,如果我將收音機移動到currentView的佈局,它會調用它。你的支票在方法中 - 但方法沒有被調用。 – user1529412 2013-04-23 20:14:12