I am making an app, where the toolbar has a menu, and within has 2-3 checkboxes.I have code put down for xml and java, and checkbox displays. But nothing gets ticked when i press. Code below
action_bar xml which gets included in main activity :
<item
android:id="@+id/eleaf"
app:actionViewClass="android.widget.CheckBox"
android:checkable="true"
android:checked="false"
android:orderInCategory="5"
app:showAsAction="never"
android:buttonTint="@color/colorAccent"
android:title="E-Leaf"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:onClick="itemClicked"/>
Java for onOptionsItemsSelected :
public boolean onOptionsItemSelected(MenuItem item)
{
boolean checked = item.isChecked();
switch (item.getItemId())
{
case R.id.eleaf:
if(checked){
Toast.makeText(this, "E-Leaf Map shown", Toast.LENGTH_SHORT).show();
item.setChecked(false);
}
break;
case R.id.biomass:
if (checked){
Toast.makeText(this, "Biomass Map shown", Toast.LENGTH_SHORT).show();
item.setChecked(false);
}
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
I had this line in oncreate but not really using it :
CheckBox checkEleaf = (CheckBox) findViewById(R.id.eleaf);
Any suggestions on how to go about this. Thanks
Aucun commentaire:
Enregistrer un commentaire