0

Each listView binding tutorial I checked but I have a strong confusion in the adapter section. First see my code

ListView listView = (ListView) findViewById(R.id.mylist);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
  "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
  "Linux", "OS/2" };

// First paramenter - Context
// Second parameter - Layout for the row
// Third parameter - ID of the TextView to which the data is written
// Forth - the Array of data
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
  android.R.layout.simple_list_item_1, android.R.id.text1, values);

// Assign adapter to ListView
listView.setAdapter(adapter); 

See this line

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
      android.R.layout.simple_list_item_1, android.R.id.text1, values);

What is this? android.R.layout.simple_list_item_1 who says that we can refer to the listeView by R???

why??? Please help

2
  • Even the simplest array binding to listview is not working. please help Commented Aug 19, 2012 at 12:55
  • Post simple_list_item_1.xml. You should have there a textview with id text1 Commented Aug 19, 2012 at 12:59

3 Answers 3

1

Check the docs:

public ArrayAdapter (Context context, int resource, int textViewResourceId, T[] objects)

Parameters

context The current context.

resource The resource ID for a layout file containing a layout to use when instantiating views.

textViewResourceId The id of the TextView within the layout resource to be populated

objects The objects to represent in the ListView.

http://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter(android.content.Context, int, int, T[])

You should have in the layout file simple_list_item_1.xml a textview with id text1.

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

Comments

0

instead of

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);

try using

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

or use

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,R.id.theTextViewID, values);

Comments

0

use the following code....

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,

android.R.layout.simple_list_item_1, values);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.