java - ListView items not changing text colour -
i've used colouring adapter change text colour of list view items after debugging app crashes , error don't know how fix. know problem lies line 77 reason not clear me. ideas on how rectify this?
package com.apptacularapps.exitsexpertlondonlite; import android.content.context; import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.adapterview; import android.widget.arrayadapter; import android.widget.listview; import android.widget.textview; public class stationchooseractivity extends actionbaractivity { listview list_linechooser; string[] listcontent = { "bakerloo line", "central line", "circle line", "district line", "hammersmith & city line", "jubilee line", "metropolitan line", "northern line", "piccadilly line", "victoria line", "waterloo & city line", "docklands light railway", "london overground", "tramlink" }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_stationchooser); list_linechooser = (listview)findviewbyid(r.id.list_linechooser); mycoloringadapter adapter = new mycoloringadapter(this,listcontent); list_linechooser.setadapter(adapter); } private class mycoloringadapter extends arrayadapter<string> { private final context context; private final string[] values; public mycoloringadapter(context context, string[] values) { super(context, r.layout.list_item, values); this.context = context; this.values = values; } @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); view rowview = inflater.inflate(r.layout.list_item, parent, false); textview textview = (textview) rowview.findviewbyid(r.id.list_item); // set text textview.settext(values[position]); // set color depending on position int textcolorid = r.color.white; // default color switch (position) { case 0: textcolorid = r.color.bakerloo; break; case 1: textcolorid = r.color.central; break; case 2: textcolorid = r.color.circle; break; case 3: textcolorid = r.color.district; break; case 4: textcolorid = r.color.hc; break; case 5: textcolorid = r.color.jubilee; break; case 6: textcolorid = r.color.metropolitan; break; case 7: textcolorid = r.color.white; break; case 8: textcolorid = r.color.piccadilly; break; case 9: textcolorid = r.color.victoria; break; case 10: textcolorid = r.color.wc; break; case 11: textcolorid = r.color.dlr; break; case 12: textcolorid = r.color.overground; break; case 13: textcolorid = r.color.tramlink; break; } textview.settextcolor(getresources().getcolor(textcolorid)); return rowview; } } }
your list item layout file name list_item
think not giving correct id textview. here
textview textview = (textview) rowview.findviewbyid(r.id.list_item);
make double sure text view id in xml file list_item
(i dont think so). in case change correct id , work hopefully.
Comments
Post a Comment