0

I'm trying to get the string from my listView item that I click.

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, list);

I have tried accessing it using:

TextView text = (TextView) arg1.findViewById(R.id.text1);

The id of the textView of android.R.layout.simple_list_item_1 is android:id="@android:id/text1" but according to Eclipse text1 cannot be resolved or is not a field

I'm sure I'm making a mistake accessing the default android textView in the simple list item, but I'm not sure how to access it. Any ideas?

1
  • 1
    Did you try it using android:id="@android:**+**id/text1" ? Commented Oct 8, 2013 at 19:16

3 Answers 3

1

ArrayAdapter has getItem(int position), you can rely on it to retrieve the string your a looking for. How did you get arg1?

Sign up to request clarification or add additional context in comments.

2 Comments

arg1 is from the onItemClickListener.
the first argument is the AdapterView. you can use the AdapterView instance to call getItemAtPosition to retrieve the string
0

This ended up working as the solution for me. Thanks for giving me the though user2433059

TextView textView = (TextView) arg1.findViewById(android.R.id.text1);
String text = textView.getText().toString();

Comments

0

text1 cannot be resolved because it is an Android resource and you won't be able to access it through your R variable.

You will fix your issue using:

TextView text = (TextView) arg1.findViewById(android.R.id.text1);
String itemText = text.getText().toString();

2 Comments

Yeah, I just posted that about 20 minutes ago. Thanks for backing me up on it though.
@GuyLeStack, sorry. Didn't realize that in time :/ Just make sure you accept one of the answers to "close" the topic.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.