1

質問があります。

名前、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)を変更する方法はありますか?

4

1 に答える 1

2

はい、可能です。ただし、独自のアダプター クラスを作成して Override する必要がありますgetView()。カスタム アダプターの作成方法に関するこのチュートリアルを読むことをお勧めします。

于 2012-11-03T00:21:08.823 に答える