android - Custom Adapter - Listview setBackground current row -
first of all, i'm trying achieve is: whenever person clicks specific button (this button on every line of listview rows), the row according button should change color.
this i've tried far without success, because gives me errors.
public view getview(int position, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); view rowview = inflater.inflate(rowresourceid, parent, false); imagebutton add_to_cart = (imagebutton) rowview.findviewbyid(r.id.add_to_cart_butt); final listview lv = (listview) rowview.findviewbyid(r.id.product_listview); final int theposition = position; add_to_cart.setclickable(true); add_to_cart.setid(position); add_to_cart.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { lv.setfocusable(true); // line error begins lv.setbackgroundcolor(color.green); } }); 10-06 15:56:19.302: e/androidruntime(1859): fatal exception: main 10-06 15:56:19.302: e/androidruntime(1859): java.lang.nullpointerexception 10-06 15:56:19.302: e/androidruntime(1859): @ classes.com.example.myexample.itemadapter$1.onclick(itemadapter.java:66) 10-06 15:56:19.302: e/androidruntime(1859): @ android.view.view.performclick(view.java:4240) 10-06 15:56:19.302: e/androidruntime(1859): @ android.view.view$performclick.run(view.java:17721) 10-06 15:56:19.302: e/androidruntime(1859): @ android.os.handler.handlecallback(handler.java:730) 10-06 15:56:19.302: e/androidruntime(1859): @ android.os.handler.dispatchmessage(handler.java:92) 10-06 15:56:19.302: e/androidruntime(1859): @ android.os.looper.loop(looper.java:137) 10-06 15:56:19.302: e/androidruntime(1859): @ android.app.activitythread.main(activitythread.java:5103) 10-06 15:56:19.302: e/androidruntime(1859): @ java.lang.reflect.method.invokenative(native method) 10-06 15:56:19.302: e/androidruntime(1859): @ java.lang.reflect.method.invoke(method.java:525) 10-06 15:56:19.302: e/androidruntime(1859): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:737) 10-06 15:56:19.302: e/androidruntime(1859): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 10-06 15:56:19.302: e/androidruntime(1859): @ dalvik.system.nativestart.main(native method)
how can solve it? thanks.
just change color of rowview. or edit tag of rowview , n make if(rowview.gettag().equals("clicked"){//changeback}else{//defaultback}
Comments
Post a Comment