-1

I'm making NLevel expandable list using listview. I've added checkbox only last level data in list view.

I want to check only one checkbox at a time. Please any one help me!

Here my code

@Override
public View getView(final NLevelItem item) {
// .......

final CheckBox checkBox = (CheckBox)view.findViewById(R.id.check);
checkBox.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        //store checkbox state, note that NLevelItem item might need to be defined with 'final'
        item.setChecked(checkBox.isChecked());

        if(checkBox.isChecked()){
            tempList.add((String) ((SomeObject)childs.getWrappedObject()).getName()+"+"+name);
        }
        else {
            tempList.remove((String) ((SomeObject)childs.getWrappedObject()).getName()+"+"+name);
        }
    }//onClick()
}//setOnClickListener()

//update checkbox state from the corresponding NLevelItem
checkBox.setChecked(item.isChecked());

//.......
}//getView()

Thanks in advance....

appu
  • 143
  • 2
  • 3
  • 15

1 Answers1

0

There's RadioButton in RadioGroup for doing that, why would you want to use checkbox

AwaisMajeed
  • 2,254
  • 2
  • 10
  • 25
  • I want only checkbox.. No need radiobutton – appu Apr 05 '17 at 07:29
  • then you can declare an int checkOptionId and store the id of checked checkbox in it....when the user checks another checkbox you can uncheck the previous one – AwaisMajeed Apr 05 '17 at 08:05