FDupie FDupie - 2 months ago 6
Android Question

Click item in listview does not work

When I click on any list item nothing happens, can someone please help or tell me where the problem is...?

Here is my Listview:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".defineBybeldbAlles">


<ListView
android:id="@+id/BybelHoofstukListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#ff303030"
android:dividerHeight="1dp"
android:layout_marginTop="5dp"
android:choiceMode="singleChoice" />
</RelativeLayout>


Here is my Listview Item:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/customButtonLayout"
android:layout_height="50dp"
style="@android:style/Widget.Button"
android:focusable="false"
android:layout_width="200dp">

<! hoofstuk_id is hidden and is only for reference >
<TextView
android:text="id"
android:id="@+id/hoofstuk_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
>
</TextView>

<TextView
android:textColor="#000"
android:text="nommer"
android:layout_height="wrap_content"
android:id="@+id/custom_row_hoofstuktext"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp">
</TextView>

</LinearLayout>

</LinearLayout>


Here is my OnItemclicklistener in the activity:

listviewHoofstuk.setOnItemClickListener(new AdapterView.OnItemClickListener(){

@Override
public void onItemClick (AdapterView<?> arg0, View view, int arg2, long arg3){

//on selecting a hoofstk
//BybelActivityVers will be launched to show verse inside

Intent hoofstukIntent = new Intent(BybelActivityHoofstuk.this,BybelActivityVers.class);

//send hoofstuk_id to VersActivity to get verse under that book

String hoofstuk_id_na_vers =((TextView)view.findViewById(R.id.hoofstuk_id)).getText().toString();
hoofstukIntent.putExtra("hoofstuk_id", hoofstuk_id_na_vers);

startActivity(hoofstukIntent);
}
});


Ive looked at a few other solutions but nothing works in my case, I added this code but it makes no difference when I use it or not:

android:focusable="false"

android:focusableInTouchMode="false"

android:descendantFocusability="blocksDescendants"

Answer

Yout list item is taking focus. Set below line in LinearLayout Tag in my Listview Item xml file

 android:clickable="false"

Your intent will fire without taking focus and work properly I ahve checked it... Let me know once its works for you...

Comments