Federico Dubbini
Federico Dubbini

Reputation: 29

How to pass button position inside listview to another activity?

Like the title, if I press a button inside the listview I want that send the position of the button to another activity

I don't know what code do you want to check what I did.

I put the method when the button is pressed, this method is inside the listadapter

   listHolderRiepilogo.btnNota.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(v.getContext() ,Pop_Nota.class);
            i.putExtra("posizione", ---WHAT TO PUT HERE---);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }
    });

Upvotes: 0

Views: 368

Answers (1)

jyoti sakhare
jyoti sakhare

Reputation: 136

make position of getView method final and send it in intent

 @Override
    public View getView(final int position, View convertView, ViewGroup parent) 
{
      listHolderRiepilogo.btnNota.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(v.getContext() ,Pop_Nota.class);
            i.putExtra("posizione", position);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }
    });
}

Upvotes: 2

Related Questions