i facing strange behavior in android listview: have disabled checkboxes in each row. when click on row seems checkboxes go enable short time before launching next activity (the result of click).
here previous click , after click :
stationsfavoritesadapter.xml:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:descendantfocusability="blocksdescendants"> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="50dp" android:background="@drawable/listviewborder"> <checkbox android:id="@+id/favorite_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" style="?android:attr/starstyle" android:layout_alignparentleft="true" android:layout_centervertical="true" android:enabled="false" /> <imageview android:id="@+id/weatherimage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@id/favorite_checkbox" /> <textview android:id="@+id/stationnametext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@id/weatherimage" android:layout_aligntop="@id/weatherimage" android:textstyle="bold" /> <textview android:id="@+id/temperaturetext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@id/weatherimage" android:layout_below="@id/stationnametext" /> <textview android:id="@+id/trailstext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/stationnametext" android:layout_alignparentright="true" android:layout_marginright="5dp" /> </relativelayout> </relativelayout>
here adapter class getview()
method :
public class stationsfavoritesadapter extends stationsadapter{ public stationsfavoritesadapter(stationsmanager stations) { _stationmanager = stations; _data = new arraylist<map.entry<string, station>>(); _data.addall(_stationmanager.getfavorites().entryset()); _stationfilterlist = _data; } @override public view getview(int position, view convertview, viewgroup parent) { final view result; if (convertview == null) { result = layoutinflater.from(parent.getcontext()).inflate(r.layout.stationsfavoritesadapter, parent, false); } else { result = convertview; } final map.entry<string, station> station = getitem(position); ((textview) result.findviewbyid(r.id.temperaturetext)).settext(station.getvalue().get_temperature() + "°c"); ((textview) result.findviewbyid(r.id.stationnametext)).settext(station.getkey()); ((textview) result.findviewbyid(r.id.trailstext)).settext(station.getvalue().get_trails().first + "/" + station.getvalue().get_trails().second); checkbox favoritebox = (checkbox)result.findviewbyid(r.id.favorite_checkbox); favoritebox.setchecked(true); imageview image = (imageview)result.findviewbyid(r.id.weatherimage); if(station.getvalue().get_weather().equals("sunny")) { image.setimageresource(r.mipmap.sunnyicon); } else if(station.getvalue().get_weather().equals("storm-clouds")) { image.setimageresource(r.mipmap.snowicon); } else { image.setimageresource(r.mipmap.cloudyicon); } return result; } }
and listview click event :
@override public void onlistitemclick(listview parent, view w, int position, long id) { string stationname = adapter.getitem(position).getkey(); intent intent = new intent(this, stationactivity.class); bundle b = new bundle(); b.putstring("station name", stationname); intent.putextras(b); startactivity(intent); }
thanks time.
your getview functions gets called eveytime app draws list view. think want do onclicklistener on list view set check box true there, not in getview
use code in activity or fragment
listview1.setonitemclicklistener(new. onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { } });