因为我写的标题我需要一些帮助这里从字符串数组中获取项目并在文本视图中逐个显示我有代码,让它们全部在列表视图,但我需要显示他们在文本视图逐个随机在这里我的代码,抱歉我的英文不好
谢谢帮忙反正…
public class MainActivity extends ListActivity {
String[] mTestArray;
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an ArrayAdapter that will contain all list items
ArrayAdapter adapter;
mTestArray = getResources().getStringArray(R.array.planets_array);
/* Assign the name array to that adapter and
also choose a simple layout for the list items */
adapter = new ArrayAdapter(
this,
android.R.layout.simple_list_item_1,
mTestArray);
// Assign the adapter to this ListActivity
setListAdapter(adapter);
}
}
XML文件:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@array/planets_array"
/>
和字符串数组文件:
Mercury
Venus
Earth
Mars