Adding Toast To Every Childitem Of A Multi Level Expandable Lisview
I found this multilevel expandable listview which is very accurate with my project, but I also want to add a different toast to every third level (which is the last layer of view)
Solution 1:
@OverridepublicvoidonFinalChildClick(int plpos, int slpos, int tlpos) {
String msg = "";
switch (tlpos) {
case0:
msg = "Shakespear is a good poet";
break;
case1:
msg = "Earth isn't flat";
break;
default:
msg = "Unknown";
}
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
@OverridepublicvoidonFinalItemClick(String plItem, String slItem, String tlItem) {
String inMsg = plItem + ", " + slItem + ", " + tlItem;
String outMsg = "";
if (inMsg.equals("group 1, Child Level 1, A")){
outMsg = "Shakespear is a good poet";
} elseif (inMsg.equals("group 1, Child Level 1, B")){
outMsg = "Earth isn't flat";
} else {
outMsg = "Unknown";
}
Toast.makeText(this, outMsg, Toast.LENGTH_SHORT).show();
}
Solution 2:
Please set this listener expandableListView.setOnChildClickListener
after the expandableListView
is initialized, that is after setUpAdapter()
in your case as expandableListView
is still null when you are trying to set the listener because your initialization of this is afterwards.
That is the reason for NullPointerException
. because expandableListView
is null while setting the listener.
Cheers
Post a Comment for "Adding Toast To Every Childitem Of A Multi Level Expandable Lisview"