The task in general such, on clicking on an item of the list, the new window opens. But the setOnItemClickListener () method does not work at all. I put logs into the method, in general the method is not involved. I broke my head already. Maybe I'm stupid where, tell me.

public class ListAdapter extends BaseAdapter { private Context context; private LayoutInflater inflater; private String[] list = new String[100]; public ListAdapter(Context context,String[]list){ this.context=context; this.inflater=LayoutInflater.from(context); this.list=list; } @Override public int getCount() { return this.list.length; } @Override public Object getItem(int i) { return null; } @Override public long getItemId(int i) { return 0; } @Override public View getView(int position, View view, ViewGroup viewGroup) { View v = this.inflater.inflate(R.layout.list_view_item, null); ((TextView)v.findViewById(R.id.tvListView)).setText(this.list[position]); Button btnList = (Button) v.findViewById(R.id.button1); ImageView imageView =(ImageView)v.findViewById(R.id.ivListItem); return v; } 

 public class MainActivity extends AppCompatActivity { final String[] list = new String[100]; private static final String TAG = "myLog"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initList(list); ListView listView = (ListView)findViewById(R.id.listView1); final ListAdapter adapter = new ListAdapter(this,list); if (listView != null) { listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.d(TAG,"метод OnItemClick"); } }); } } public void initList(String[] list){ for(int i=0; i<list.length; i++){ list[i]=i+" "; } } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public void onSettingsMenuClick(MenuItem item) { Intent intent = new Intent(this,SettingsActivity.class); startActivityForResult(intent,0); } 
  • one
    stackoverflow.com/questions/5551042/… And this ... round out with a ListView besides without a Holder, recyclerView is our everything. - Yura Ivanov
  • There is an option that you do not just see the logs? If your list is displayed, the adapter will work. Try Toast cram. So there are no obvious errors, there are a couple of unnecessary lines in the adapter, everything should work. - Shwarz Andrei
  • 2
    @ShwarzAndrei click fails because of Button, which is focusable ... - Yura Ivanov
  • Well, yes, in the markup, the button hangs all right. I talked about these lines - Shwarz Andrei
  • one
    everything, figured out, focus set to false and earned! THANKS - onetwothree

1 answer 1

Add for your button:

 android:focusable="false"