Charles Lynch
Charles Lynch

Reputation: 221

Taking value from another class from adapter

I need help here. I'm trying to take a value from my class and take it to another class to be processed.... My problem is, the value is from an adapter. I'm stuck here.

Here is my code :

lv.setOnItemClickListener(new OnItemClickListener()
{
 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
 {
     //Toast.makeText(getApplicationContext(), data.get(arg2).toString(),3000).show();
     Intent newI = new Intent (this, PDetail.class); 
     startActivity (newI);
 }});

This is the class i want to call (PDetail.class) :

public class PDetail extends Activity {
 //Create ct;
 Toast.makeText(getApplicationContext(), data.get(arg2).toString(),3000).show();
}

My question is, how can i get the "data" value from the first class??? Any suggestion appreciated.

Upvotes: 0

Views: 521

Answers (1)

user2633519
user2633519

Reputation: 11

In your first activity

lv.setOnItemClickListener(new OnItemClickListener()
{
 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
 {
     Intent newI = new Intent (this, PDetail.class); 
     newI.putExtra("value",data.get(arg2));
     startActivity (newI);
 }});

In your second activity

   String value =getIntent().getStringExtra("value");

I hope it can help you.

Upvotes: 1

Related Questions