2012-05-10 10 views
1

私は自分のカスタムXMLファイルでこのリストビューを持っています。Androidの設定イメージはリスト内に表示されます

ファイルには、固定IDを持つソースセットのない画像があります。

私はこのイメージソースを私のリソースのうちの1つに変更したいと考えています。ここで

は私のXMLである:これは私がこれまで試してみました何であり、それがクラッシュし

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
> 
<ImageView 
android:id="@+id/listImage" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:contentDescription="protection image" 
android:layout_marginTop="10dp" 
/> 
<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:layout_marginLeft="10dp" 
> 
<TextView android:id="@+id/text1" 
android:textSize="20dp" 
android:textStyle="bold" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"/> 
<TextView android:id="@+id/text2" 
android:textSize="12dp" 
android:layout_marginTop="5dp" 
android:layout_width="wrap_content" 
android:layout_height="fill_parent"/> 
</LinearLayout> 
</LinearLayout> 

</LinearLayout> 

 adapter=new SimpleAdapter(this, listItems, R.layout.custom_row_view,new String[]{"name", "current"}, new int[] {R.id.text1, R.id.text2}); 
    ImageView img; 
    img = (ImageView) findViewById(R.id.listImage); 
    Drawable d = getResources().getDrawable(R.drawable.opened); 
    img.setImageDrawable(d); 
    setListAdapter(adapter); 
+0

uが同じ画像に各リスト項目のすべてのリスト項目または異なる画像を設定したいのですか? – KMI

+0

私は2つの画像を持っています。どの画像がどの画像になるのかを決定する必要があります。 – arielschon12

+0

画像を決定する条件は何ですか? –

答えて

1
ImageView img; 
    img = (ImageView) findViewById(R.id.listImage); 

これは、あなたが持つオブジェクトを参照していることを意味しアクティビティののsetContentView()に使用していたレイアウト内に存在しますが、そのレイアウトにはImageViewは存在しません。

ここでは、これをListViewで参照しようとしています。だから明らかにnullポインタの例外が発生しています。

カスタムアダプターも使用する必要があります。下のリンクから試してみてください。

http://www.ezzylearning.com/tutorial.aspx?tid=1763429&q=customizing-android-listview-items-with-custom-arrayadapter

http://www.mkyong.com/android/android-listview-example/

+0

私はこれらの例を理解していますかわかりません..私はIDを持っている場合、単に画像を変更するための簡単な方法はありませんか? – arielschon12

+0

No.カスタムリストビューでは不可能です。カスタムアダプターのみを使用する必要があります。 –

+0

まあ、リストビューには2行あります。これも適応可能ですか? – arielschon12

関連する問題