0

MainView( ExpandableListView)からRadioButtondefinedを取得しchild_row.xml、リスナーを設定しますが、OnCheckChanged呼び出されません。現在のビューに移動RadioButtonすると、呼び出されます。

どうすればこれを修正できますか?

私は持っている ....

  1. mainListView.xml //expandableListView
  2. group_row.xml //textView
  3. 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();
        }
    }

}
4

1 に答える 1

0

使用した完全なコードを提供していません。後でその膨張したchildViewActivityのレイアウトに追加する場合は、何らかの形で をブロックしていないかどうかを確認するために、メイン レイアウトを提供する必要がありますCheckBox。レイアウトを膨張させるだけの場合、そのchildViewは画面上のどこにも作用しないため、checked イベントが発生しないのは正常です。

CheckBoxコードの外観から、の子に のリスナーを設定したいようですExpandableListView。これがあなたの望むものであるなら、それは間違った試みであり、それを行う方法はあなたの 用のカスタムアダプタを使うことですExpandableListView. カスタム アダプターの作成と子要素へのリスナーの設定に関するチュートリアル (およびここでの質問) がたくさんあります。

于 2013-04-24T06:11:33.433 に答える