2012-06-08 11 views
8

ListView内の項目の固定進捗を設定しようとしています。私はリストビュー内の不確定な回転円を見るだけです....私は間違って何をしていますか?リストビュー内のAndroidプログレスバーは常に不確定です

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

答えて

12

最も簡単な方法は、それに水平なスタイルを適用することです:これは、すべての属性を設定します

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

あなたがそうでなければ確定プログレスモードを適用するには、手動で追加する必要があります。

あなたは好奇心旺盛であれば、このようなケースでは、あなたが個別にプロパティを適用したい、のようなそのシステムのスタイルが見えるものです:

<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

それはそれをしました!私はこれがもう少し明白であったと思う。 –

0
次のアダプタレイアウトXMLの

を(私はちょうどそれを見ていないよ...答えは簡単であると確信しています)

indeterminate modeをfalseに変更してください!

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

私はこれを試してみました、これはそれを修正しませんどちらか。 –

関連する問題