2016-05-16 3 views
-2

私は専用のPCに自分のuTorrentのダウンロードに関するいくつかのデータを含む "Torrent"クラスを持っているかもしれません。 ArrayList<Torrent> torrentsは毎秒バックグラウンドで更新中です。 したがって、私はRecyclerView.Adapterを既知のパターンのように持っています。ViewHolderのonBindViewHoleder()メソッドのロジックは?

@Override 
public void onBindViewHolder(final MyViewHolder holder,int position){ 
    ... 
    // Update ETA textView 
    holder.tvEta.setText(String.format(Locale.getDefault(),"%d h %d min %d s",torrents.get(position).getEta()/3600,(torrents.get(position).getEta()%3600)/60,torrents.get(position).getEta()%60)); 
    ... 
} 

をしかし、この場合にはを動作していない: 、、私に教えてくださいWHYこのコードは完璧に働いていますか?それはちょうど、スタートの最初の値を更新し、より多くを変更しない:アダプターのライト内部

@Override 
public void onBindViewHolder(final MyViewHolder holder,int position){ 
    ... 
     // Update ETA textView 
     int secs = torrents.get(position).getEta(); 
     int hours = secs/3600; 
     int minutes = (secs % 3600)/60; 
     int seconds = secs % 60; 
     holder.tvEta.setText(Locale.getDefault(), String.format("%d h %d min %d s", hours, minutes, seconds)); 
    ... 
} 

答えて

0

1つの方法

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> implements View.OnClickListener { 

.... 
ArrayList<Torrent> torrentList; 

public void addItems(ArrayList<Torrent> torrents) 
{ 
torrentList = torrents; 
notifyDataSetChanged(); 
} 

@Override 
public int getItemCount() { 
return torrentList.size(); 
    } 
..... 
..... 
} 
あなたの主な活動で

public class MainActivity extends Activity 
{ 
    ... 
    ... 
mAdapter.addItems(torrentList); 
    ... 
} 
+0

以下のように動作しません。..まだ変わっていない... – rbaloo

関連する問題