Newaj Kabir Newaj Kabir - 1 year ago 68
Android Question

How to pass text from listView item to a new activity

I am using SimpleCursorAdapter to fetch data from SQLite database to a listView. Now I am trying to open an activity which will contain the text from the listView. I have written the code, but wherever I click, it is showing only the first item's text. Code is given below:

listView.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub

textView = (TextView) findViewById(;

String text = textView.getText().toString();

Intent intent = new Intent(getApplicationContext(), SingleActivity.class);
intent.putExtra("com.example.practise.write", text );



Code in SingleACtivity class :

protected void onCreate(Bundle savedInstanceState) {

textTextView = (TextView) findViewById(;

Intent intent = getIntent();
String write = intent.getStringExtra("com.example.practise.write");


Answer Source

You need to get the textview of selected item then you will get the correct value If list item is just the TextView you can cast it to TextView like this

TextVie view = (TextView) view; 

or if your textview is a sub view of your list item view then do this.

TextView textView = (TextView) view.findViewById(;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download