Home > Mobile >  How to pass textview value from adapter class to texview of another acivity
How to pass textview value from adapter class to texview of another acivity

Time:02-15

I want to pass the value of textview from the adapter class to another textview of another activity. please help me ...

//recycleradapter class

Intent intent = new Intent(applicationContext, DetailActivity.class);
            
            intent.putExtra("likes",holder.quantity.toString());
            applicationContext.startActivity(intent);

// detail acivity class

String like = getIntent().getStringExtra("Likes");
Toast.makeText(this, like "", Toast.LENGTH_SHORT).show();
item_quantiy.setText(like);

CodePudding user response:

Do it in two steps.

  1. get the value from the adapter to the activity
  2. Then send the data from this activity to the other

Use an interface to trigger when the item in the recyclerview in clicked

In the interface implementation in the activity get that data and pass it to the next activity via an intent like you're doing here

CodePudding user response:

change

Intent intent = new Intent(applicationContext, DetailActivity.class);
intent.putExtra("likes",holder.quantity.toString());
applicationContext.startActivity(intent);

to

Intent intent = new Intent(applicationContext, DetailActivity.class);
intent.putExtra("likes",holder.quantity.getText().toString());
applicationContext.startActivity(intent);

CodePudding user response:

Check your key spelling. as you can see in your code the key is likes with small l and in your DetailActivity the key is Likes with capital L Change the code as below

Intent intent = new Intent(applicationContext, DetailActivity.class);  
intent.putExtra("likes",holder.quantity.toString());
applicationContext.startActivity(intent);

to

String like = getIntent().getStringExtra("likes");
Toast.makeText(this, like, Toast.LENGTH_SHORT).show();
item_quantiy.setText(like);

or you can create a class to store your keys like below

public class SC{ 
     private static final String KEY_LIKE = "likes"
}

then you can call this key in any class like SC.KEY_LIKE

CodePudding user response:

in adapter use context or activity for intent .(instead applicationContext)

  • Related