由于 ListView 中的项目内容有点复杂,我的 ListView 需要几秒钟才能滚动到特定项目。所以我想添加一个 Indeterminate 进度条以使其流畅。
要滚动到特定项目,我使用 listView.setSelection(n) 来做到这一点。然后我倾向于使用“setOnItemSelectedListener”事件处理程序来隐藏滚动后的进度条。但是事件处理程序没有被调用。
可能是我的概念完全错误,我不知道该怎么做(像这种情况下使用进度条)。如果您向我展示这个概念,也欢迎提供更多详细信息。
非常感谢。
public class ListViewAdapter extends BaseAdapter {
private ProgressBar progressBar;
private Handler progressBarHandler = new Handler();
boolean isProgressBarDone;
private void jumpToSelectedItem(View arg0) {
...
listView.setSelection(selectedDaYunItem);
}
ListView listView = (ListView)((MyActivity)cellView.getContext()).findViewById(R.id.listview);
listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
// onItemSelected event handler has not triggered.
@Override
public void onItemSelected(AdapterView<?> arg0,
View arg1, int arg2, long arg3) {
isProgressBarDone = true;
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
public class LiouYunCellAdapter {
cellView.setOnTouchListener(new View.OnTouchListener() {
// It takes a little seconds to operate.
private void jumpToSelectedItem(View arg0) {
....
}
@Override
public boolean onTouch(View arg0, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
progressBar = findProgressBar(arg0);
// ProgressBar start.
new Thread(new Runnable() {
public void run() {
isProgressBarDone = false;
while (!isProgressBarDone) {
// Update the progress bar
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setVisibility(View.VISIBLE);
}
}
});
}
}).start();
jumpToSelectedItem(arg0);
}
}
return true;
}
});
// End setOnTouchListener().
}
// end class LiouYunCellAdapter.
}