Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android list view clickable problem

i have this customized list. each row contains an image and two lines of text one below the other. i want to open a new activity when any list item is clicked. but i am not able to do so, even after implementing the setOnItemClickListener(). please correct me if i am wrong. the below is the code for the list. PS: This is an normal activity and not list activity.

l1.setAdapter(new EfficientAdapter(this,eventTitleArray,eventDateArray,eventImageLinkArray));
   //l1 = getListView();
   l1.setClickable(true);
   l1.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1,
      int position, long arg3) {
     Intent intent = new Intent(MainActivity.this, DisplayActivity.class);
     Bundle b = new Bundle();
     b.putString("event", eventTitleArray[position]);
     intent.putExtras(bundle);
     startActivity(intent);

     Toast.makeText(getApplicationContext(), "Opening detailed view for:"+eventTitleArray[position], Toast.LENGTH_SHORT).show();


    }
   });
like image 595
i_raqz Avatar asked Nov 30 '10 17:11

i_raqz


People also ask

How list view works in android?

A list view is an adapter view that does not know the details, such as type and contents, of the views it contains. Instead list view requests views on demand from a ListAdapter as needed, such as to display new views as the user scrolls up or down. In order to display items in the list, call setAdapter(android.

What is setAdapter in android studio?

setAdapter(new ArrayAdapter<String>(this,R. layout. drawer_list_item, mServices)); This line is mapping an array of strings ( mServices ) for display in a ListView ( mDrawerList ).


2 Answers

Please have a look whether the row layout has any items which are focusable. If an ListView Item contains focusable children, the Listview Handler will not be fired.

like image 156
Michael Avatar answered Sep 20 '22 19:09

Michael


I think there is a bug in the SDK that prevents the onItemClickListeners from firing when there are focusable views in the View of your items.

So you should try to do a setFocusable(false) on all the Views of your items.

The problem is described here

like image 23
nbarraille Avatar answered Sep 18 '22 19:09

nbarraille