Я только начинаю с Android и не могу найти, как отобразить список в моей деятельности.
Активность и макет main.xml показаны ниже.
Как я могу отобразить массив стран в «List» ListView моего макета?
спасибо
Июль
public class Atable extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String[] COUNTRIES = new String[] { "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra"};
setListAdapter(new ArrayAdapter<String>(this, R.layout.main, COUNTRIES)); //I tried this but it does not work
}
main.xml
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search" />
<EditText android:id="@+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView android:id="@id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/noresults"/>
</LinearLayout>
</LinearLayout>