gpt4 book ai didi

android - 在 ListView 的每个项目中显示 ProgressBar

转载 作者:太空狗 更新时间:2023-10-29 14:32:30 26 4
gpt4 key购买 nike

我想为 ListView 的每个项目添加一个 ProgressBar

我正在像这样将适配器添加到 ListView

RankAdapter adapter=new RankAdapter(model);
list.setAdapter(adapter);

RankAdapterRankHolder类如下

class RankAdapter extends CursorAdapter {
RankAdapter(Cursor c) {
super(RankNew.this, c);
}

@Override
public void bindView(View row, Context arg1, Cursor c) {
// TODO Auto-generated method stub

RankHolder holder = (RankHolder) row.getTag();

holder.populateForm(c, helper);
}

@Override
public View newView(Context ctxt, Cursor c, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.rankvalues, parent, false);

RankHolder holder = new RankHolder(row);
row.setTag(holder);

return row;
}
}

class RankHolder {

private TextView url = null;
private TextView googletext = null;
private TextView alexatext = null;
private View row = null;

RankHolder(View row) {

this.row = row;
url = (TextView) row.findViewById(R.id.newrankurl);
googletext = (TextView) row.findViewById(R.id.newrankgoogle);
alexatext = (TextView) row.findViewById(R.id.newrankalexa);
}

void populateForm(final Cursor c, final RankHelper helper) {
url.setText(helper.getUrl(c));
googletext.setText(helper.getGoogle(c));
alexatext.setText(helper.getAlexa(c));
}
}

最佳答案

将 ProgressBar 添加到您的 Xml并在 java 文件中这样做

class RankAdapter extends CursorAdapter
{

RankAdapter(Cursor c){
super(RankNew.this,c);
}

@Override
public void bindView(View row, Context arg1,final Cursor c) {
// TODO Auto-generated method stub

final RankHolder holder=(RankHolder)row.getTag();
holder.populateForm(c,helper);
}

@Override
public View newView(Context ctxt, Cursor c, ViewGroup parent) {
LayoutInflater inflater=getLayoutInflater();
View row=inflater.inflate(R.layout.rankvalues,parent,false);
RankHolder holder=new RankHolder(row);
dialogmain.dismiss();
row.setTag(holder);
return row;
}
}




class RankHolder{
private TextView url=null;
private TextView googletext=null;
private TextView alexatext=null;
private View row=null;
private ProgressBar mSpinner=null;

RankHolder(View row){
this.row=row;
mSpinner =(ProgressBar)row.findViewById(R.id.progress);
mSpinner.setIndeterminate(true);
mSpinner.setVisibility(View.VISIBLE);
url=(TextView)row.findViewById(R.id.newrankurl);
googletext=(TextView)row.findViewById(R.id.newrankgoogle);
alexatext=(TextView)row.findViewById(R.id.newrankalexa);
}

void populateForm(final Cursor c,final RankHelper helper){
new Thread(){
public void run(){
try{
Thread.sleep(300);
}catch(Exception e){
}
thhandler.sendEmptyMessage(0);
}
}.start();
thhandler=new Handler(){
@Override
public void handleMessage(Message msg){
super.handleMessage(msg);
mSpinner.setVisibility(View.INVISIBLE);
}
};
url.setText(helper.getUrl(c));
if(flag==0){
updateValues(helper.getUrl(c).toString());
}
googletext.setText(helper.getGoogle(c));
alexatext.setText(helper.getAlexa(c));
}
}

关于android - 在 ListView 的每个项目中显示 ProgressBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5076931/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com