2012-06-08 25 views
8

Tôi đang cố gắng đặt tiến trình cố định trên các mục trong một ListView. Tôi chỉ thấy một vòng tròn không xác định trong ListView .... tôi đang làm gì sai? (Tôi chắc chắn câu trả lời là đơn giản ... Tôi chỉ không nhìn thấy nó)Thanh tiến trình Android trong chế độ xem danh sách luôn không xác định

Đối với cách bố trí bộ chuyển đổi xml sau:

<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" 
     /> 

Code:

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; 
} 
} 

Trả lời

12

Cách đơn giản nhất là để áp dụng phong cách ngang với nó:

<ProgressBar 
    android:id="@+id/some_progress" 
    style="@android:style/Widget.ProgressBar.Horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    /> 

này sẽ thiết lập tất cả các thuộc tính bạn sẽ khác cần phải thêm bằng tay để áp dụng một chế độ tiến bộ quyết tâm.

Nếu bạn tò mò, đây là những gì mà phong cách hệ thống có vẻ như, trong trường hợp bạn muốn áp dụng các thuộc tính riêng lẻ:

<style name="Widget.ProgressBar.Horizontal"> 
    <item name="android:indeterminateOnly">false</item> 
    <item name="android:progressDrawable">@android:drawable/progress_horizontal</item> 
    <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item> 
    <item name="android:minHeight">20dip</item> 
    <item name="android:maxHeight">20dip</item> 
</style> 

HTH

+0

Điều đó đã làm được! Tôi ước điều này rõ ràng hơn một chút. –

0

Thay đổi số indeterminate mode thành sai!

<ProgressBar 
    android:id="@+id/some_progress" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:indeterminate="false" 
    /> 
+1

Tôi đã cố gắng này và điều này không sửa chữa nó hoặc. –

Các vấn đề liên quan