主程序代码:import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;public class DActivity extends ListActivity {
private List<Map<String, Object>> data;

//-----------------------------------------------
private int process = 1; //进度条当前进度

//-----------------------------------------------

public DActivity() {
data = new ArrayList<Map<String, Object>>();

Map<String,Object> map1 = new HashMap<String, Object>();
map1.put("img", R.drawable.auto);

Map<String,Object> map2 = new HashMap<String, Object>();
map2.put("img", R.drawable.benz);

data.add(map1);
data.add(map2);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
MyAdapter adapter = new MyAdapter(DActivity.this);
this.setListAdapter(adapter);
}


public class MyAdapter extends BaseAdapter {
private Context context;
private LayoutInflater inflater;

public MyAdapter(Context context) {
this.context = context;
inflater = LayoutInflater.from(context);
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return data.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;
}
private ViewHolder holder = null;

@Override
public View getView(int position, View convertView, ViewGroup parent) {

if(convertView == null) {
convertView = inflater.inflate(R.layout.d_list, null);
holder = new ViewHolder();

holder.image = (ImageView)convertView.findViewById(R.id.iv);
holder.button = (Button)convertView.findViewById(R.id.b);
holder.bar = (ProgressBar)convertView.findViewById(R.id.p);

convertView.setTag(holder);

} else {
holder = (ViewHolder)convertView.getTag();
}
holder.image.setBackgroundResource((Integer)data.get(position).get("img"));
holder.button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if(v.getId() == R.id.b) {
new ProgressBarThread().start();

}

}
});
return convertView;
}

}

static class ViewHolder {
static ImageView image;
static Button button;
static ProgressBar bar;
}

private boolean isStop; class ProgressBarThread extends Thread {
public void run() {

synchronized ("abc") {
while (!isStop) {
if (process > ViewHolder.bar.getMax()) {
break;
}

Message mess = new Message();
Bundle bundle = new Bundle();
bundle.putInt("process", process++); mess.setData(bundle);
handler.sendMessage(mess); try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
}
}

// 消息处理器,负责配合UI线程更新进度条
private Handler handler = new Handler() { @Override
public void handleMessage(Message msg) {
Bundle bundle = msg.getData();
int process = bundle.getInt("process");
ViewHolder.bar.setProgress(process);
super.handleMessage(msg);
} };
}
配置文件xml<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:layout_height="wrap_content" android:id="@+id/iv"
android:layout_width="wrap_content"></ImageView>
<Button android:text="下载" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/b"></Button>
<ProgressBar style="?android:attr/progressBarStyleHorizontal"
android:layout_height="wrap_content" android:id="@+id/p"
android:layout_width="150dp"></ProgressBar></LinearLayout>
效果图如下:
不论点哪个按钮,都是下面那个在下载,多半是代码问题,但是不知道怎么改