1
単純なListActivityを拡張して各アイテムの横に小さなイメージを表示したいと考えています。ここに私のコードは、これまでのところです:各項目の画像を追加するためのAndroid拡張ListActivity?
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight" />
MainActivity.java:
public class MainActivity extends ListActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Create an array of Strings, that will be put to our ListActivity
String[] names = new String[] { "some", "list", "items", "which", "each", "have", "their", "own", "image"};
this.setListAdapter(new ArrayAdapter<String>(this,R.layout.main, names));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// Get the item that was clicked
Object o = this.getListAdapter().getItem(position);
String keyword = o.toString();
Toast.makeText(this, "You selected: " + keyword, Toast.LENGTH_SHORT)
.show();
}
}
そして、私は10個の項目(列)のように持っているとそれぞれには、私はそれに隣り合わせにしたい画像があります。 itemImage1.png、itemImage2.png、...など
どうすればいいですか?
ありがとうございました。
ねえをオーバーライドし、キーコードになりそうだおかげで、私はちょうど種類のわからない、これを実装する方法です。 item.xmlファイルはどのようなものですか?データオブジェクトとは何ですか?この行は何ですか:imageLoader.DisplayImage(data [position]、activity、holder.image); ?おかげで – JDS
のように見えるデータは、URLのString []です。 imageLoader.DisplayImageは最初の引数(URL)を取得し、画像をダウンロードして3番目の引数(リスト項目)に読み込みます。 xmlには、textviewとimageviewが含まれている必要があります。あなたのリストの1行を表すものと考えてください。 アクティビティとURLの文字列[]をリストアクティビティに渡す必要があります。テキストの文字列[]を渡したい場合は、簡単に変更できます。私はちょうどコードをダウンロードして、その中を突っ込んできた。何かがあれば、あまりにも多くの細部を理解しなくても簡単に実装する必要があります。 – marklar