Reputation: 15
in Listview items, i have 3 textview, and i want to send this String values(textviews) by clicking on each item separately.... i mean by clicking on item no.1 , using intent i could reach 4 strings in that item from other activity...here is my code:
lvMsg = (ListView) findViewById(R.id.listView);
//.
//. using cursor and attach it to adapter
//.
adapter = new SimpleCursorAdapter(this, R.layout.row, c,
new String[]{"_id","address", "body"}, new int[]{
R.id.textView6, R.id.textView5, R.id.textView7});
lvMsg.setAdapter(adapter);
lvMsg.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
Intent i=new Intent(MainActivity.this,otherActivity.class);
//???message should be ??
i.putExtra( "MESSAGE" , message);
startActivity(i);
}
});
thanks...
Upvotes: 1
Views: 1169
Reputation: 144
if you mean you want to pass each item value by click on it then
message should be
String message = adapter.getItem(position).toString;
edit
String message = ((TextView)adapter.getItem(position)).getText().toString();
Upvotes: 0
Reputation: 163
If i understand correctly your question...Get the text for each textview to a string and send it...
lvMsg.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
String _id = ((TextView) view.findViewById(R.id.textView6)).getText().toString();
String address = ((TextView) view.findViewById(R.id.textView5)).getText().toString();
String body = ((TextView) view.findViewById(R.id.textView7)).getText().toString();
Intent i=new Intent(MainActivity.this,otherActivity.class);
//???message should be ??
String message = id + address + body;
i.putExtra( "MESSAGE" , message);
startActivity(i);
}
});
Upvotes: 1
Reputation: 77
try this one.
lvMsg.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
TextView v = (TextView) view.findViewById(R.id.R.id.textView6);
//to pass id value
Intent i=new Intent(MainActivity.this,otherActivity.class);
i.putExtra( "MESSAGE" , v.getText());
startActivity(i);
}
});
Upvotes: 0