我想在ListView中的項目上設置一個固定的進度。我只能在ListView中看到一個不確定的旋轉圈......我做錯了什麼? (我敢肯定的答案很簡單......我只是沒有看到它)在listview中的Android進度條總是不確定
對於下列適配器佈局XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/some_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<ProgressBar
android:id="@+id/some_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
代碼:
public class SomeListAdapter extends ArrayAdapter<MyItem> {
private static class ViewHolder {
TextView nameTextView;
ProgressBar valueProgressBar;
}
public BestChoiceListAdapter(Context context, List<MyItem> items) {
super(context, R.layout.list_item, items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
View view = convertView;
if (view == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.nameTextView = (TextView) view.findViewById(R.id.some_text);
holder.valueProgressBar = (ProgressBar) view.findViewById(R.id.some_progress);
view.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
MyItem optionItem = getItem(position);
holder.nameTextView.setText(optionItem.getOptionName());
int progress = (int) (optionItem.getOptionValue());
holder.valueProgressBar.setProgress(progress);
return view;
}
}
這樣做!我希望這更明顯。 –