Android Expandlistview Group ImageView Error Resolution

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.