2014-12-22 2 views
0

Привет Я пытаюсь динамически загружать ImageView в ListView, этот код не работает.Dynamic Loading Image View

public View getView(int position, View convertView, ViewGroup parent) { 
... 
    String uri = "@drawable/"+myImage[position]; 
    int imageResource = mycontext.getResources().getIdentifier(uri, null, mycontext.getPackageName()); 
    ImageView imageview= (ImageView) convertView.findViewById(R.id.imgPic); 
    Drawable res = mycontext.getResources().getDrawable(imageResource); 
    imageview.setImageDrawable(res); 
} 

Вход

android.content.res.Resources$NotFoundException: Resource ID #0x0 
     at android.content.res.Resources.getValue(Resources.java:1195) 
     at android.content.res.Resources.getDrawable(Resources.java:729) 
     at android.content.res.Resources.getDrawable(Resources.java:711) 
     at parser.my.myapplication.NotificationAdapter.getView(NotificationAdapter.java:77) 
+0

Сообщения Вашего LogCat –

+0

я добавил журнал –

ответ

1

Нет необходимости добавлять "@drawable/" перед тем вытяжку name.Get вытяжки идентификатор с помощью getIdentifier:

String uri = myImage[position]; 
int imageResource = mycontext.getResources().getIdentifier(uri, 
             "drawable", mycontext.getPackageName()); 
imageview.setImageResource(imageResource); 
+0

его предоставление андроиду. content.res.Resources $ NotFoundException: Идентификатор ресурса # 0x0 в строке: Drawable res = mycontext.getResources(). getDrawable (imageResource); –

+0

@RonDavis: см. Мой ответ –

+0

сейчас изображение пуст. Пустое изображение просматривается. –