I want nothing but my app to display the strings on the main activity, all that happens when the app opens is the array of strings is displayed. Nothing more nothing less. Can not seem to find this information anywhere!
3 Answers
You can use ListView component.
list_cars.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="20sp" >
</TextView>
public class ListCarsActivity extends ListActivity {
static final String[] CARS = new String[] { "BWM", "Volvo", "Mersedes-Benz",
"Honda", "Toyota", "Nexia", "Wolkswagen", "CHevrolet",
"Ferrari", "Volga", "Porshe", "Bentley", "Bugatti" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// it is not needed
// setContentView(R.layout.list_cars);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_cars,CARS));
ListView listView = getListView();
listView.setTextFilterEnabled(true);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_SHORT).show();
}
});
}
}
Can not seem to find this information anywhere!?