setOnItemClickListener not responding for Custom ListView

I wrote a custom Adapter for a listview ,but when i tried implement click event for list item ,i found that it was not responding ,I will be glad if someone suggest me a solution.

public class TourList extends ListActivity {

getListView().setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
                     //i couldn't reach here
             Log.v(TAG,"did u get me");
adap = new MyAdapter(TourList.this,mylist);

and my custom adapter is

  • How to check crash log using android ndk in cocos2d-x
  • How to play song in Android - phonegap
  • Android FragmentStatePagerAdapter returns blank screen when reloading middle fragments
  • How to set a long click listener on a MenuItem (on a NavigationView)?
  • sometimes remaining in memory (hprof dumps)
  • How can I put titles in ViewPager using fragments?
  • private class MyAdapter extends BaseAdapter {
                ArrayList<HashMap<String,String>> elements;
                Context ctx;
                public MyAdapter(Context context, ArrayList<HashMap<String,String>> mylist) {
                public boolean isEnabled(int position){
                   return true;
                public int getCount() {
                    return elements.size();
                public Object getItem(int position) {
                    return elements.get(position);
                public long getItemId(int position) {
                    return position;
                public View getView(int position, View convertView, ViewGroup parent) {
                    View v = convertView;
                    if (convertView == null) {
                          LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                          v = vi.inflate(R.layout.rowfor_tourlist, null);
                        TextView in = (TextView)v.findViewById(;
                        TextView du = (TextView)v.findViewById(;
                        TextView pf = (TextView)v.findViewById(;
                        TextView pn = (TextView)v.findViewById(;
                        WebView wv=(WebView)v.findViewById(;  
                    return v;

    and my tourlist.xml file looks like

     <ListView android:id="@id/android:list"

    Related posts:

    Fixing debug.keystore to work with ADT 22 and Google Maps v1 API Key
    SQLiteConstraintException not caught
    Android Facebook SDK v4 LikeView issue
    Design support library - Which version to use with SDK v21
    Android&#039;s ArrayAdapter - add strings listview instead of replace
    Android - Live Wallpaper offset clipping
  • How can you listen to click events on a ListView that occur outside of the list items?
  • Passing String array between two class in android application
  • Android: make interaction to switch between activity like Chrome's Tab Management
  • Confusion between OpenCv4Android and C++ data types
  • When an internet connection is present and I click on “check update” in Android Studio, I get “Connection Failed”
  • Build works in debug, fails in release - ZipException duplicate entry
  • 2 Solutions collect form web for “setOnItemClickListener not responding for Custom ListView”

    See if this discussion helps…

    The question is really simple.

    You cannot call setOnItemClickListener before setAdapter call because ListView relies on its children and its children are unknown until you set the adapter.

    So simply do like this:

    public class StatusListView extends ListView implements OnItemClickListener {
        private StatusListAdapter adapter;
        public StatusListView(Context context) {
        private void init() {
            // do other things
            adapter = new StatusListAdapter(getContext(), R.layout.status_list_item, statuses);
            // pay attention here
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            StatusListAdapter adapter = (StatusListAdapter) ((ListView) adapterView).getAdapter();
            Status status = (Status) adapter.getItem(position);
            Intent intent = new Intent(getContext(), CustomActivity.class);
            intent.putExtra(C.extra_keys.status, status);

    In this way you will have your event up and running !
    Sorry but I didn’t time to go in detail in Android source code, if I will I will post again.

    Bye guys,

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.