2

I have a list view with a custom adapter. the layout for the adapter has some ImageViews which act as buttons. I implemented the onclicklistner for these

listView.setOnItemClickListener(new OnItemClickListener() {

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

        ImageView btn = (ImageView) arg1.findViewById(R.id.btn);
        btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
            // TODO Auto-generated method stub
            // for the  button action
            Log.d("Button Action", "Clicked");
            }
        });

    }


}

when i click the button first time it does not do any thing .i have to click twice to get the button work. Why is this. can any one point me my mistake

thanks in advance

Chamila Adhikarinayake
  • 3,588
  • 5
  • 25
  • 32

2 Answers2

3

Check this is very good Example for Custom listview with Buttons...

Custom ListView with Button

SilentKiller
  • 6,944
  • 6
  • 40
  • 75
0

I advise you to check the above link by Aze it is really brilliant.

I think the first button click gets focus on the on the list item.

Amt87
  • 5,493
  • 4
  • 32
  • 52
  • this should be in comment n no it will not go in as the focus is given to listView check the example code given by me bro,,.. @Amt87 – SilentKiller Aug 14 '12 at 10:27