タイトルで書いています。私はここで文字列配列から項目を取得し、テキストビューで1つずつ表示するための助けが必要です。リストビュー内のすべてが、私はここで、ランダムな1でテキストビュー1で私の悪い英語 、とにかく助けてくれてありがとう...アンドロイド:文字列配列からアイテムを取得し、それをテキストビューで1つずつ表示
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>
ランダムにまたは連続して表示しますか? –
Pls。私のansをチェックしてください。あなたの質問が答えられたらpls。 ansを受け入れる。 :) – lokoko
あなたはリストビューを望んでいません、そうですか?あなたの配列値をランダムに表示するtextViewだけですか? – Devrim