我正在显示带有一些电影和右侧显示按钮的 Listview 以供下载,但是当我每次滚动 Listview 然后按钮事件交换(重绘)时,当用户按下下载按钮并开始下载但向下滚动列表时,我设置了按钮文本取消按钮文本通过下载和事件获取交换更改初始名称。
static class listitemcontainers
{
//ImageView imgIcon;
//TextView txtTitle;
ProgressBar pb;
TextView progressval;
Button downloadbutton;
TextView title;
ImageView imageicon;
LinearLayout layout;
}
@Override
public View getView(int position, View convertview,final ViewGroup parent) {
// TODO Auto-generated method stub
final listitemcontainers holder;
Log.d("Game Name in adapter",":"+GameListname.get(position));
View vi=convertview;
final listitemcontainers holdz;
RelativeLayout RL;
if(convertview==null)
{
convertview = inflater.inflate(R.layout.list_row, null);
holder = new listitemcontainers();
holder.title = (TextView)convertview.findViewById(R.id.game_name);
holder.imageicon=(ImageView)convertview.findViewById(R.id.listicon);
RL=(RelativeLayout)convertview.findViewById(R.id.game_row);
holder.layout = (LinearLayout )convertview.findViewById(R.id.dynamic);
holder.progressval=(TextView)convertview.findViewById(R.id.progressval);
holder.pb=(ProgressBar)convertview.findViewById(R.id.progressBar1);
holder.pb.setVisibility(View.INVISIBLE);
holder.downloadbutton=(Button)convertview.findViewById(R.id.button1);
convertview.setTag(holder);
final listitemcontainers hold = holder;
//setButtonClick(hold );
}
else {
holder = (listitemcontainers)convertview.getTag();
}
holder.title.setText(GameListname.get(position));
holder.imageicon.setImageDrawable(GameIcon.get(position));
holder.downloadbutton.setText("Dwnload"+position);
holder.downloadbutton.setId(position);
holder.pb.setId(position+1000);
setButton(holder,convertview,position);
return convertview;
}
int globalid;
public void setButton(final listitemcontainers holder,final View v,final int id){
holder.downloadbutton=(Button)v.findViewById(id);
holder.pb=(ProgressBar)v.findViewById(id+1000);
holder.downloadbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(activity, "Click By:"+id, Toast.LENGTH_SHORT).show();
if(checkflag==true){
checkflag=false;
globalid=id;
UpdateProgresBar.listcntr=holder;
up=new UpdateProgresBar(holder.pb,activity,v);
up.execute("");
CancleButtonClick(holder,v,id);
}
else{
Toast.makeText(activity, "Please wait", Toast.LENGTH_SHORT).show();
}
}
});
}