0
我显示Listview与一些电影和右侧显示按钮下载,但当我滚动列表查看然后按钮事件交换(重绘)每次,我有设置按钮文本取消时,用户按下载按钮和下载开始,但向下滚动时列表然后按钮文本更改与下载和事件获取交换的初始名称。Android如何在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();
}
}
});
}
如何更改名称?邮政编码。 – 2013-05-02 12:57:20
你应该看看我的新库,这使得写入适配器变得更容易..当然包括你需要的 - 在你的项目中添加可点击的按钮。 http://amigold.github.io/FunDapter/ – Ami 2013-05-20 19:57:35