I have a piece of code
public class Radio_groupActivity extends ListActivity {
TextView selection;
String[] items={"One", "Two", "Three"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1));
}
}
Now I have the main.xml in the folder but I don’t have any xml file called simple_list_item_1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/selection"
/>
<ListView android:layout_height="fill_parent"
android:id="@+id/list"
android:layout_width="fill_parent"></ListView>
</LinearLayout>
So, what’s the relationship of the listview with @id/list and that android.R.layout.simple_list_item_1?
The
android.package qualifier inandroid.R.layout.simple_list_item_1means you’re referring to an Android framework resource rather than a resource from your app. You may not have a layout by that name, but the Android framework does.ListActivity looks for a ListView with the id
@android:id/listwhen usingsetListAdapter.