質問があります。
名前、ID、タイプなどが異なるデータベース(配列)を作成しました。また、名前を読み取る文字列を作成しました(名前は文字列です:
public static String[] getAllPokemonsInStrings() {
ArrayList<String> items = new ArrayList<String>();
for(Pokemon p : Pokemon.values()){
if(p.getName() != null){
items.add(p.getName());
}
}
return items.toArray(new String[]{});
}
これを作成するビットは次のとおりです。
public class Test3 extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, Types.getAllPokemonsInStrings() ));
}
}
そして行ごとのxml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/LinearLayout">
<ImageView
android:id="@+id/sprite"
android:layout_width="96dp"
android:layout_height="96dp"
android:contentDescription="@string/sprite"
android:src="@drawable/p002" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
配列からロードして、行ごとにそれを行うimageresource(int)を変更する方法はありますか?