how to get a list item position by clicking the button inside it?

前端 未结 8 587
余生分开走
余生分开走 2020-12-09 16:48

actually I\'ve read some previous questions about this...

this is the code that I use

auto = (ListView)findViewById(R.id.auto);
String[] projection =         


        
8条回答
  •  执念已碎
    2020-12-09 17:34

    do you execute this

    btnNxt = (Button) findViewById(R.id.btnNext);
     btnNxt.setOnClickListener(new OnClickListener() {
     @Override
     public void onClick(View arg0) {
      //Here I need to get that position
    });
    

    inside the getView method? if so it's very easy

     btnNxt = (Button) findViewById(R.id.btnNext);
     btnNxt.setTag(position);
     btnNxt.setOnClickListener(new OnClickListener() {
     @Override
     public void onClick(View arg0) {
      int position=(Integer)arg0.getTag();
    });
    

    from this: https://stackoverflow.com/a/20542034

提交回复
热议问题