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 8093607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:32:16+00:00 2026-06-05T20:32:16+00:00

I am currently working on android project where I am using a custom list

  • 0

I am currently working on android project where I am using a custom list view which TextViews for each item. I am settings the displayable text by using myTextView.setText("my text") and then setting the TextView tag by using myTextView.setTag("my tag").

Once its in the list view I then want to allow the user to click on the item within the list view and retrieve the textview text as well as the tag.

I’ve tried TextView textView = (TextView)getListAdapter().getItem(position);
and “TextView textView = (TextView)getListView().getItem(position); but it keeps saying that it can’t can’t from String to TextView.

How can I get the tag and the text from the text view.

Thanks for any help you can provide.

UPDATE 1
As requested this is a ListActivity that I am using and below is the code for the item click event

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

    //get selected items
    //String selectedValue = (String) getListAdapter().getItem(position);
    //TextView textView = (TextView)appArrayAdapter.getItem(position);
    TextView textView = (TextView)getListView().getChildAt(position);
    String selectedValue = textView.getText().toString();
    String selectedPackage = textView.getTag().toString();
    Intent intent = new Intent();
    intent.putExtra("appName", selectedValue);
    intent.putExtra("packageName", selectedPackage );
    setResult(0, intent);
    finish();
}

And the below code is the code that sets the list adapter

final ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>)pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);

        ArrayList<String> arrayList = new ArrayList<String>();
        imageList = new ArrayList<Drawable>();
        packageName = new ArrayList<String>();
        for(int i = 0; i != list.size(); i++)
        {
            String text = list.get(i).activityInfo.applicationInfo.loadLabel(pm).toString();
            String appPackage = list.get(i).activityInfo.packageName;
            arrayList.add(text);
            Drawable imageId = list.get(i).activityInfo.applicationInfo.loadIcon(pm);
            packageName.add(appPackage);
            imageList.add(imageId);
        }

        appArrayAdapter = new AppArrayAdapter(this, arrayList);
        //setListAdapter(new AppArrayAdapter(this, arrayList));
        setListAdapter(appArrayAdapter);

    }

And the below code is the appArrayExtender class

public class AppArrayAdapter extends ArrayAdapter<String>
    {
        private final Context context;
        private final ArrayList<String> arrayList;
        //private final ArrayList<Drawable> imageList;

        public AppArrayAdapter(Context context, ArrayList<String> arrayList/*, ArrayList<Drawable> imageList*/)
        {
            super(context, R.layout.select_apps, arrayList);
            this.context = context;
            this.arrayList = arrayList;
            //this.imageList = imageList;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent)
        {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View rowView = inflater.inflate(R.layout.select_apps, parent, false);
            TextView textView = (TextView)rowView.findViewById(R.id.label);
            ImageView imageView = (ImageView)rowView.findViewById(R.id.logo);

            textView.setText(arrayList.get(position));
            textView.setTag(packageName.get(position));
            imageView.setImageDrawable(imageList.get(position));
            //imageView.setImageResource(R.drawable.icon);
            return rowView;
        }
    }

And below is the XML for the layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/logo"
        android:layout_width="50px"
        android:layout_height="50px"
        android:layout_marginLeft="5px"
        android:layout_marginRight="20px"
        android:layout_marginTop="5px" >
    </ImageView>

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label" >
    </TextView>


</LinearLayout>
  • 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-05T20:32:18+00:00Added an answer on June 5, 2026 at 8:32 pm

    If you want the text from the TextView, use the information passed into the onClick rather than all that extra code. The framework passes in the view that was clicked on (the View v parameter). If it is a single TextView, you can do v.getText().toString(), if it is a more complex layout, you can use v.findViewById(R.id.TextView1) to get the proper TextView and the use getText().toString() on it:

    @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) { 
    
        TextView textView = (TextView) v.findViewById(R.id.yourRowLayoutWidget);  // get the widget contained in the layout
        String selectedValue = textView.getText().toString(); // get the value of the widget into a string
        // do what you will with the string
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a project which involves optical character recognition in Android and
I am currently working on an android project which lists all of the apps
I am currently working on an Android project. I am using a ListView and
I'm currently working on a Android+AppEngine project using voice as my main input method.
currently i am working with the Android's APK expansion files. By using the sample
I’m currently working on a Android project and is very newbie to the Android
I'm working on an Android project and I'm currently playing around with JSoup to
I'm currently working on a Wrapper for Android, Which wraps an android apk with
I am working on a university project, which involves profile and event management using
I'm currently working on migration of iPhone project to Android. And since my dev

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.