當我在標題中寫入時,我需要一些幫助以獲取字符串數組中的項目,並在文本視圖中逐個顯示它我有代碼所有在列表視圖,但我需要一個每個隨機這裏我的代碼和對不起我的英語不好 ,感謝您的幫助反正時間顯示他們在文本視圖一個...android:從字符串數組中獲取項目並在文本視圖中逐個顯示
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<String> 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<String>(
this,
android.R.layout.simple_list_item_1,
mTestArray);
// Assign the adapter to this ListActivity
setListAdapter(adapter);
}
}
XML文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@array/planets_array"
/>
</RelativeLayout>
和字符串數組文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
</string-array>
</resources>
你想讓它們隨機或按順序顯示嗎? –
請注意。檢查我的答案。如果你的問題是回答請。接受答案。 :) – lokoko
你不想要一個listView,對不對?只有一個textView隨機顯示你的數組值? – Devrim