Ammar Ijaz
Ammar Ijaz

Reputation: 105

OnItemClickListener not working for ListView using custom adapter

OnItemClickListener not working for ListView even list is not clickable as well here is my code

    pListView=(ListView) findViewById(R.id.plist);
    pListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView parent, View v, int position, long id){

            Log.d("here","in item list click");


        }
    });

and xml is below

<ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/plist"
        android:layout_gravity="center"
        android:alpha="1" />

Upvotes: 0

Views: 870

Answers (1)

Anton Kazakov
Anton Kazakov

Reputation: 2764

You doing it wrong so your OnItemCLick method in OnItemClickListener interface is not overrided. Seems like you just typed all this stuff. Android Studio will generate it for you. Just print new OnItem... in .setOnItemClickListener() and let the studio do the magic.

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        }
    });

Upvotes: 2

Related Questions