0

GridView'im, bir İndirme düğmesinin bulunduğu görünümlerden oluşur. Düğmeye dokunduğunuzda gizlenir ve bir ilerleme çubuğu görüntülenir. İlerleme çubuğu, İndir düğmesine basıldığında başlayan bir Servis tarafından güncellenir.GridView neden farklı hücreleri karıştırıyor gibi görünüyor?

Elimde olan sorun, belirli bir öğe için bir indirme başlatırsam ve ardından aşağı kaydırıyorsa, ilerleme çubuğunun, indirilmemesi gereken hücrelerde görülebildiğini fark ettim. Bunun muhtemelen GridView geri dönüşüm hücrelerine bağlı olduğunu düşünüyorum, ama tamamen emin değilim. Aşağıdaki kodun bir kısmını yayınladım. Gerekirse daha fazla yayınlayabilirim.

GetView -

private void downloadFile(MNBook book, final ProgressBar progressBar, 
           final Button downloadButton, final Button readButton) { 
     final MNBook localBook = book; 
     String fileName = book.getFileName(); 
     String url = book.getURL(); 
     Intent intent = new Intent(this, DownloadService.class); 
     intent.putExtra("url", url); 
     intent.putExtra("file_name", fileName); 
     intent.putExtra("receiver", new ResultReceiver(new Handler()) { 
      @Override 
      protected void onReceiveResult(int resultCode, Bundle resultData) { 
       super.onReceiveResult(resultCode, resultData); 
       if (resultCode == DownloadService.UPDATE_PROGRESS) { 
        int progress = resultData.getInt("progress"); 
//     mDetailFragment.setProgress(progress); 
//       mProgressDialog.setProgress(progress); 
        progressBar.setProgress(progress); 
        if (progress == 100) { 
         progressBar.setVisibility(View.GONE); 
         readButton.setVisibility(View.VISIBLE); 
         setDownloadedBookStatus(localBook); 
        } 
       } 
      } 
     }); 
     downloadButton.setVisibility(View.GONE); 
     progressBar.setVisibility(View.VISIBLE); 
     startService(intent); 

    } 

cevap

0

DownloadFile yöntemi

GridView'da

public View getView(final int position, View convertView, ViewGroup parent) { 
      final RelativeLayout card; 
      if (convertView == null) { 
       card = (RelativeLayout) getLayoutInflater().inflate(R.layout.book_cover, null); 
      } else { 
       card = (RelativeLayout) convertView; 
      } 
      TextView bookName = (TextView) card.findViewById(R.id.textView_bookName); 
      TextView authorName = (TextView) card.findViewById(R.id.textView_bookAuthor); 
      final MNBook currentBook = getItem(position); 
       bookName.setText((String) currentBook.getTitle()); 
      authorName.setText((String) currentBook.getAuthor()); 
      final Button downloadBookButton = (Button) card.findViewById(R.id.button_download_book); 
      final Button readBookButton = (Button) card.findViewById(R.id.button_read_book); 
      final ProgressBar progressBar = (ProgressBar) card.findViewById(R.id.progressbar_book_download); 
      readBookButton.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        Intent intent = new Intent(); 
        intent.setAction(Intent.ACTION_VIEW); 
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { 
         intent.setDataAndType(Uri.fromFile(new File(getExternalFilesDir(null), 
             currentBook.getFileName())), 
           "application/pdf"); 
        } 
        startActivity(intent); 
       } 
      }); 
      downloadBookButton.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        downloadFile(currentBook, progressBar, 
          downloadBookButton, readBookButton); 
       } 
      }); 
      if (currentBook.isBooleanDownloaded()) { 
       downloadBookButton.setVisibility(View.GONE); 
       readBookButton.setVisibility(View.VISIBLE); 
       progressBar.setVisibility(View.GONE); 
      } 

//    ImageView bgImage = (ImageView) card.findViewById(R.id.myImageView); 
      Resources resources = getApplicationContext().getResources(); 
//    final int resourceId = resources.getIdentifier(mCategoryImages[position], "drawable", 
//      getApplicationContext().getPackageName()); 
//    bgImage.setImageResource(resourceId); 
      return card; 
     } 
için Adaptörü Sen, her getView() çağrı üzerine Widget görünürlüğünü güncellemek için bunlardan sadece bazıları gerekir. Bu, her getView() çağrısında bulunan metin veya görüntülerin widget'lara ayarlanmasından farklı değildir. GridView gibi AdapterView ve RecyclerView sınıflarındaki widget'lar geri dönüştürülür. Bir getView() aramasındaki ProgressBar numarasını gösterirseniz ve bu widget geri dönüştürülür ve özellikle geri dönüştürülmüş getView() araması için gizlemezseniz, ProgressBar yine de görünür olacaktır.

İlgili konular