大家好,
我有一个问题困扰了我 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" />
//我的网格视图