lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView adapterview, View view,
int position, long id) {
doSomething();
}
});
这是我的主要活动代码。我制作了自定义列表视图,当然还有定制的ArrayAdapter。在listview的每一行中,我都有一个进度条,我在ArrayAdapter
方法getView()
处设置了进度条视图。像这样是我的ArrayAdapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ProgressBar bar = (ProgressBar)convertView.findViewById(R.id.progressbar);
}
private void updateProgressBar(){
//blah blah
}
所以我的问题是:当我通过点击主Activity上的一行listview来执行doSomething()
方法时,它会触发updateProgressBar()
类中的ArrayAdapter
方法并更新进度条视图在那一行。所以想象一下,如果我点击三行,那么每行的三个进度条将开始运行。我怎么可能实现这个目标?
答案 0 :(得分:2)
好吧,您可以使用adapter
获取该项目并激活特定项目的progressbar
,或者您可以在创建时向每行添加clicklistener
并在getview()
内更新lv
{1}}
我希望这会有所帮助
例如,假设ListView
为ProgressBar
并假设您的invisible
为visible
,并且当有人点击时您只是lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
doSomething(view, yourListArray.get(position), position);
}
});
private void doSomething(View view, YourItem item, int position){
((ProgressBar)view.findViewById(R.id.list_progress)).setVisibility(View.VISIBLE);
//do whatever you want here, you have the item, the view and even the position in case you need something
//else, in fact this maybe should be a thread so whenever you finish doing whatever you want, in the
//handler of the thread you make the ProgressBar invisible again
}
关于项目
{{1}}
我希望这会有所帮助