我有堅持我的第2天,一個問題,正如你所看到的圖像,我只啓動進程#1和更新過程來處理吧,但是當我向下滾動我看到另一個「進程酒吧「運行,它具有與我的第一個(#1)相同的進程狀態。我想我的ListView
項目被重複使用,它也使用我的進程欄,是否有人遇到這個問題?我還附上代碼如下,
感謝您的閱讀
class gridAdapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
String currentText = list.get(position);
View cell = convertView;
if(cell==null){
LayoutInflater inflater = MainActivity.this.getLayoutInflater();
cell = inflater.inflate(R.layout.gird_tiem, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) cell.findViewById(R.id.tv_test);
viewHolder.button = (Button) cell.findViewById(R.id.button);
viewHolder.progressBar = (ProgressBar) cell.findViewById(R.id.process);
cell.setTag(viewHolder);
}
final ViewHolder holder = (ViewHolder) cell.getTag();
holder.text.setText(currentText);
holder.button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
processManager.onAddItemClick(100, holder.progressBar);
}
});
return cell;
}
}
static class ViewHolder {
public TextView text;
public Button button;
public ProgressBar progressBar;
}
//我的流程管理
public class ProcessManager {
Activity activity;
public ProcessManager(Activity activity) {
super();
this.activity = activity;
}
int temp;
public void onAddItemClick(final int tasks, final ProgressBar cell) {
new Thread(new Runnable() {
@Override
public void run() {
for(int i = 0;i<tasks;i++){
temp = i;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
}
});
thread.run();
try {
thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
cell.setProgress((temp*100)/tasks);
}
});
}
}
}).start();
}
//我的產品
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/tv_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="XXXX" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Process"
android:id="@+id/button"
android:focusable="false" />
<ProgressBar
android:id="@+id/process"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100" />
//我的網格視圖
你可以發佈你的progressBars裏面的xml佈局嗎? – Opiatefuchs 2013-05-10 14:03:20
你應該在'onAddItemClick()'方法中修改你的代碼。這些項目自己開始進度,因爲您認爲引用的'ProgressBar'對每一行都是不同的,因爲'ListView'回收行是不正確的。 – Luksprog 2013-05-10 14:14:37