2013-08-19 2 views
0

Я стараюсь ленивое изображение загрузки изображений внутри диалога.Получение внутреннего диалогового окна за пределами диалогового окна

Моя проблема заключается в том, что я не могу получить представление из своего диалогового окна за пределами диалогового окна для обновления изображений.

Я пытаюсь дать каждому виду уникальный идентификатор, а затем найти представление по его идентификатору, но я получаю исключение из null-указателя.

Вот мой диалог код:

public void showAllComents() { 

     builderComment = new AlertDialog.Builder(this); 

     builderComment.setTitle(dietsList[poisition][0] + " comments"); 

     View prefView = View.inflate(this, R.layout.show_comments, null); 

     builderComment.setCancelable(false); 

     editComment = (EditText) prefView.findViewById(R.id.editComment); 

     LinearLayout commentsLinear = (LinearLayout) prefView.findViewById(R.id.commentsLinear); 

     if (haveComments) { 

      int length = comments.length; 

      for (int i = 0; i < length; i++) 
      {   
       LinearLayout tempLinear = new LinearLayout(this); 

       LayoutParams p1 = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 

       if (i != 0) 
       p1.setMargins(0, 20, 0, 0); 

       tempLinear.setOrientation(LinearLayout.HORIZONTAL); 
       tempLinear.setLayoutParams(p1); 

       ImageView image = new ImageView(this); 
       p1 = new LayoutParams(64, 64); 
       image.setLayoutParams(p1); 
       image.setId(6000+i); 
       image.setImageDrawable(getResources().getDrawable(R.drawable.anonymous)); 

       tempLinear.addView(image); 

       commentsLinear.addView(tempLinear); 
      } 

... 
... 
... \\\Rest of dialog code... 

я загрузить свои изображения, а затем я пытаюсь обновить imageviews.

public void setCommentedUsersProfilePictrue() 
     { 
      int lengthUnique = commentsuniqueNames.length; 
      int loadLength = comments.length; 

      View prefView = View.inflate(this, R.layout.show_comments, null); 

      for(int i = 0; i < loadLength; i++) 
      { 
       for(int j = 0; j < lengthUnique; j++) 
       { 
        if(comments[i][1].equals(commentsuniqueNames[j])) 
        { 
         Log.i("user name comment", comments[i][1]); 
         //Log.i("user name", userProfilePictures[i][1]); 

         ImageView tempImage = new ImageView(DietWall.this); 

         tempImage = (ImageView) prefView.findViewById(6000 + i); 

         if(tempImage != null && commentsLoadedPictrues[j][1] != null && commentsLoadedPictrues[j][1].equals("null") == false && commentsLoadedPictrues[j][1].equals("NULL") == false) 
          tempImage.setImageDrawable(new BitmapDrawable(getResources(),decodeBase64(commentsLoadedPictrues[j][1]))); 
         else 
          Log.i("null", "null"); 
        } 
        } 
       } 
       } 
+0

разместим ваш LogCat здесь .. –

+0

Мой журнал для («нулевой», «нулевой») – dasdasd

ответ

1

вам нужен вид вашего диалога, вы должны найти свой ImageView так:

View ImageView image = dialog.findViewById(R.id.image); 

, но я предлагаю использовать следующую библиотеку, она заботится о загрузке изображений/кэширование и многое другое , он просто делает вашу жизнь легче ;-)

https://code.google.com/p/android-query/#Image_Loading

//fetch and set the image from internet, cache with file and memory 
aq.id(R.id.image1).image("http://www.vikispot.com/z/images/vikispot/android-w.png"); 

Особенности:

  • Простой
  • памяти & Кэширование файлов
  • Субдискретизация
  • Масштабируемые (WebView)
  • Запасной Изображение
  • Предзагрузка
  • Анимация
  • Динамический Формат
  • Избегайте Дублированный Одновременная Выдает
  • обратного вызова
+0

Его рабочий, спасибо! – dasdasd