0
嘿即時嘗試讓一個列表工作,在這種情況下,我有一個XML定義的項目,我膨脹在擴展ArrayAdapter。但我有充氣XML後,然後當我試圖抓住了ImageView的,它通過findviewbyid返回null ... 下面是該項目的xml:ImageView仍然爲空,findby後查看
@Override
public View getView(int position, View convertView, ViewGroup parent) {
SimpleListItem item= items.get(position);
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.product_item, null);
if(item.getPicture()!=null)
{
ImageView imgVw = (ImageView) findViewById(R.id.product_item_imageview);
String picturePath = item.getPicture();
Bitmap picture = ImageManager.get(getBaseContext(), picturePath);
imgVw.setImageBitmap(picture);
} else {
TextView txtVw = (TextView) findViewById(R.id.product_item_textview);
txtVw.setText(item.getText());
txtVw.setVisibility(View.VISIBLE);
}
return v;
}
:那instatiates項目
<?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="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/product_item_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="if no image avail show this"
android:visibility="gone"/>
<ImageView
android:id="@+id/product_item_imageview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible"
/>
</LinearLayout>
方法
ImageView的imgVw =(ImageView的)訴得到它們。 findViewById(R.id.product_item_imageview); –
感謝您的快速響應,只是自己找到了它。不知道這是如何充氣工作。學習更多東西的好日子:-D –