tags:

views:

570

answers:

1

Hi i have a question about the ListView and how to use it. My Prolem is that my listView is only a part of the view and im not shure how to do this..

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

 ListView myListView = (ListView) findViewById(R.id.ListView01);
 String[] strings = new String[]{"Test1","Test2"};
 ArrayAdapter<String> myArrayAdapter= new ArrayAdapter<String>(this, R.id.ListView01,strings);
 myListView.setAdapter(myArrayAdapter);

I think the problem is the "this" in myArrayAdapter!?

+4  A: 

The layout resource id you're supposed to pass to ArrayAdapter is a layout that's used to render each item in the list, not the layout for the list itself. Android provides some layout resources for the common cases. Try using:

ArrayAdapter<String> myArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strings);
Aaron
thanks very much:)
Sponge