Custom Single choice ListView

前端 未结 4 744
滥情空心
滥情空心 2020-12-01 01:16

I want to make a custom List View having Two TextViews and a radio Button in a single row. And on listitem click the radio button state should be toggle. I cannot use Simple

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 01:37

    Handled a similar issue with a Hack (Not a perfect solution..but still works..)

     listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView parent, View view, int position, long id) {
    
    
    
    
                    for (int i = 0; i < parent.getCount() ; i ++)
                    {
    
                        View v = parent.getChildAt(i);
                        RadioButton radio = (RadioButton) v.findViewById(R.id.radio);
                        radio.setChecked(false);
    
                    }
    
                        RadioButton radio = (RadioButton) view.findViewById(R.id.radio);
                        radio.setChecked(true);
    
    
    
                }
            });
    

提交回复
热议问题