0

Эй, я пытаюсь получить список, работающий, в этом случае у меня есть определенный xml элемент, который я раздуваю в расширенном ArrayAdapter. Но после того, как я раздул XML, а затем, когда я пытаюсь захватить ImageView, он возвращает нуль по findviewbyid ... Вот XML для элемента:ImageView все еще null, после findbyView

<?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> 

Метод, который instatiates деталь:

@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; 
    } 
+0

ImageView imgVw = (ImageView) ст. findViewById (R.id.product_item_imageview); –

+0

Благодарим за быстрый ответ, просто нашли его сами. не знал, как это работает надув. Отличный день, чтобы узнать больше вещей :-D –

ответ

3

Его,

ImageView imgVw = (ImageView) v.findViewById(R.id.product_item_imageview); 

также же для TextView,

TextView txtVw = (TextView) v.findViewById(R.id.product_item_textview); 

Используйте View v для получения ImageView и TextView из вашего завышенного XML-файла.

1

// вы раздувание макета в представлении V, так что вам нужно, чтобы получить их

ImageView imgVw = (ImageView)v. findViewById(R.id.product_item_imageview); 


TextView txtVw = (TextView)v. findViewById(R.id.product_item_textview); 
Смежные вопросы