Pergunta

As said in title I am Not Getting OnItemClick Event of ListView

My code :

ListView listView1 = (ListView) findViewById(R.id.listView1);

listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            Toast.makeText(SelectQuizActivity.this, "OnItemClick", Toast.LENGTH_LONG).show();
        }
    });
    SimpleAdapter adapter = new SimpleAdapter(this, listView, R.layout.list_layout, new String[]{"topic","by","score"}, new int[]{R.id.textViewTopic,R.id.textViewTopicCreator,R.id.textViewScore});
    listView1.setAdapter(adapter);

Layout XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".SelectQuizActivity" >
<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/bg_dark_gradient_rev"
    android:gravity="center_horizontal"
    android:padding="20dp"
    android:text="@string/app_name"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@color/white"
    android:textStyle="bold"
    android:typeface="sans" />
<ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:choiceMode="singleChoice"
    android:clickable="true"
    android:divider="@drawable/bg_light_gradient"
    android:dividerHeight="1dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:listSelector="@drawable/list" >
</ListView>
</RelativeLayout>
Foi útil?

Solução

try adding focusable="false" in every child of the single row layout file. It worked for me.. :)

Update: Adding android:descendantFocusability to Parent View will also work.

Outras dicas

Try this:

listView1.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() 
{
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
    {
        Log.i("CLICK", "CLICK CLICK");
    }
});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top