In Expandlistview group if contains imageview found, error. Tip the ImageView cannot be converted to TextView. View Source Discovery, Simpleexpandablelistadapter the following methods:
private void BindView (view view, map<string,?> data, string[] from, int[] to) { int len = to.length; for (int i = 0; i < len; i++) { TextView v = (TextView) View.findviewbyid (To[i]); if (v! = null) { v.settext (String) data.get (From[i]);}}}
It can be seen that bindview all the view as TextView to deal with. It's totally out of the simpleadapter of Big Brother. You can automatically determine type bindings. The common way to do this online is to rewrite the BindView method:
public class Myexpandablelistadapter extends baseexpandablelistadapter{private void BindView (view view, Map<str ING,?> data, string[] from, int[] to) {int len = to.length; Boolean isbound = false; for (int i = 0; i < len; i++) {final View v = View.findviewbyid (to[i]); if (v!=null) {final Object _data = Data.get (From[i]); String Text = _data = = null? "": data.tostring (); if (text = = null) {text = ""; if (Mviewbinder! = null) {//If binder is not empty, use binder to process IsB Ound = Mviewbinder.setviewvalue (V, Data.get (From[i]), text); } if (!isbound) {//If Binder is skipped, use the original method for processing TextView _ v = (TextView) v; _v.settext (String) data.Get (From[i])); } } } }}
However, for me, try not to rewrite the SDK does not recommend your method of replication, because the performance and security after the replication is difficult to guarantee, it is best to let the original SDK to deal with. Continue to view the source code and find that when the type we return is not a view type, but rather an exact layout type, the SDK will be able to identify and no longer be treated as textview, so my solution is to convert Convertview to the layout type of my layout file:
@Override public View getgroupview (int groupposition, Boolean isexpanded, View Convertview, ViewGroup parent) { Itemviewholder holder = null; if (Convertview = = null) { holder=new itemviewholder (); Convertview = inflater.inflate (R.layout.down_exam_vitem, null); Holder.itemimg = (ImageView) Convertview.findviewbyid (r.id.exam_vitem_img); Convertview.settag (holder); } Else{holder = (Itemviewholder) convertview.gettag (); } Itemview = (relativelayout) Convertview; return itemview; }
Android Expandlistview Group ImageView Error resolution