2011-03-29 141 views
1

我有一個由Fedor製作的代碼,它可以找到「here」。自定義ListView?

第一個圖像是什麼,我現在有,

和第二圖像是我想要完成的任務。

有人可以指導我這個。我一直在努力解決這個問題。 請幫助我,在此先感謝!

enter image description here

enter image description here

回答

0

您只需修改列表項目佈局(在item.xml中)即可擁有其他ImageView。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="wrap_content"> 
    <ImageView android:id="@+id/image1" android:layout_width="50dip" 
     android:layout_height="50dip" android:src="@drawable/stub" 
     android:scaleType="centerCrop" /> 
    <ImageView android:id="@+id/image2" android:layout_width="50dip" 
     android:layout_height="50dip" android:src="@drawable/stub" 
     android:scaleType="centerCrop" /> 
    <TextView android:id="@+id/text" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:layout_weight="1" 
     android:layout_gravity="left|center_vertical" android:textSize="20dip" 
     android:layout_marginLeft="10dip" /> 
</LinearLayout> 

並修改LazyAdapter的getView()方法來添加對第二個ImageView的支持。

+0

我試着玩LazyAdapter.class,但我應該改變那裏解決我的問題? – 2011-03-29 17:12:32

0

一種用於創建自定義的ListView教程可以在這裏找到: http://justcallmebrian.com/?p=139

只需要改變的XML佈局,每個項目有2個ImageViews像羅比說。然後在你的適配器的getView(LazyAdapter如果你與別人的答案跟着一起),你應該有這樣的事情:

ImageView的圖像1 =(ImageView的)findViewById(R.id.image1); image1.setResource(R.drawable.icon1); ImageView image2 =(ImageView)findViewById(R.id.image2); image2.setResource(R.drawable.icon2); TextView text =(TextView)findViewById(R.id.text); text.setText(「我有2張圖片」);

我前面粘貼的教程描述了一種方法,使列表動態的生成(即沒有R.drawable.icon1/2的資源,並沒有爲文本圖像的文本)。這樣的事情可能工作(假設你有一個模型類,將持有的所有3條信息):

int resid1 = context.getResources().getIdentifier("com.domain.sub:drawable/" + myList.get(position).getImage1Name, null, null); 
ImageView image1 = (ImageView) findViewById(R.id.image1); 
image1.setResource(resid1); 
int resid2 = context.getResources().getIdentifier("com.domain.sub:drawable/" + myList.get(position).getImage2Name, null, null); 
ImageView image2 = (ImageView) findViewById(R.id.image2); 
image2.setResource(resid2); 
TextView text = (TextView)findViewById(R.id.text); 
text.setText(myList.get(position).getText()); 

當然上面的段假定你有一個ArrayList名爲myList中也getter方法獲取圖像的名稱和要顯示的文字。