Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8287409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:01:56+00:00 2026-06-08T12:01:56+00:00

I was wondering how I can get a string from a clicked listview’s item.

  • 0

I was wondering how I can get a string from a clicked listview’s item. For example I have an entry in this format.

# – John Smith

john@gmail.com

3451234532

New York

I want to get John Smith. I can get the item on that position but I don’t know the rest.

My codes:

package com.example.deneme;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;


public class Activity2 extends Activity {

private SQLiteAdapter mySQLiteAdapter;
 ListView listContent;
 SimpleCursorAdapter cursorAdapter;
 Cursor cursor;
 Button buttonDeleteAll,buttonDeleteRow;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);


buttonDeleteAll = (Button)findViewById(R.id.deleteall);
buttonDeleteRow = (Button)findViewById(R.id.deleterow); 
listContent = (ListView)findViewById(R.id.contentlist);
listContent.setClickable(true);
buttonDeleteAll.setOnClickListener(buttonDeleteAllOnClickListener);
buttonDeleteRow.setOnClickListener(buttonDeleteRowOnClickListener);


mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToWrite();



cursor = mySQLiteAdapter.queueAll();
String[] from = new String[]{ SQLiteAdapter.COLUMN_NAME, SQLiteAdapter.COLUMN_EMAIL,SQLiteAdapter.COLUMN_PHONE, SQLiteAdapter.COLUMN_ADDRESS};

int[] to = new int[]{R.id.text1, R.id.text2,R.id.text3, R.id.text4};

cursorAdapter = new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
listContent.setAdapter(cursorAdapter);



listContent.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {

        String str = ((TextView)arg1).getText().toString();
        Toast.makeText(Activity2.this, str, Toast.LENGTH_SHORT).show();
    }
});



}


   Button.OnClickListener buttonDeleteRowOnClickListener = new Button.OnClickListener(){

       public void onClick(View arg0) {

     //    String n = inputContent1.getText().toString();
     //    mySQLiteAdapter.deleteRow(n);
           updateList();
           Toast.makeText(Activity2.this, "Entry Deleted", Toast.LENGTH_SHORT).show();      


       }
        };

        Button.OnClickListener buttonDeleteAllOnClickListener
        = new Button.OnClickListener(){
       public void onClick(View arg0) {

        mySQLiteAdapter.deleteAll();
        updateList();
        Toast.makeText(Activity2.this, "All Entries Deleted", Toast.LENGTH_SHORT).show();      

       }
        };

        private void updateList(){
              cursor.requery();
               }
}

After using your way, I got hese errors:

07-27 07:52:15.726: E/AndroidRuntime(856): FATAL EXCEPTION: main
07-27 07:52:15.726: E/AndroidRuntime(856): java.lang.ClassCastException:              android.widget.LinearLayout
07-27 07:52:15.726: E/AndroidRuntime(856):  at  com.example.deneme.Activity2$3.onItemClick(Activity2.java:58)
07-27 07:52:15.726: E/AndroidRuntime(856):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
07-27 07:52:15.726: E/AndroidRuntime(856):  at android.widget.ListView.performItemClick(ListView.java:3513)
07-27 07:52:15.726: E/AndroidRuntime(856):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:01:58+00:00Added an answer on June 8, 2026 at 12:01 pm

    Well, it depends on what you’ve populated your listview with. If those are TextView’s then all you have to do is this:

    ((TextView)arg1).getText().toString()
    

    Essentially View arg1 is the clicked View. Given that you’ve populated that list, you know what that view is, because you’re the one who created and returned it in(in your adapter):

    public View getView(int position, View convertView, ViewGroup parent)
    

    Therefore, whatever the type of that View, check its the documentation to see how to get the text out of it

    Edit:

    Well, the cursor adapter you’re using returns a LinearLayout for each row. It has several TextViews, one for each column that’s selected. To get the first column you do this:

    LinearLayout row = (LinearLayout)((LinearLayout)arg1).getChildAt(0);
    TextView column = (TextView)row.getChildAt(0);
    String text = column.getText().toString();
    

    If you want a different column just change the argument to getChildAt(i)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object that I can get a String from during debugging. That
I was wondering how I can get the graphics card model/brand from code particularly
Hi I have a question. Wondering how do I get certain values from the
I'm wondering how I can get my textbox to only accept digits and dots,
I am wondering how I can get the document title in LaTex, for use
I am wondering how I can get all the files with File Info and
I am just wondering how i can get the error causing LoginUser function to
I was just wondering how I can get a single tap to undo the
I am fairly new to Android programming and was wondering how I can get
I'm using VS 2010, and I'm wondering how I can get my c++ program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.