单独修改ListView中的ProgressBars

时间:2017-01-08 16:02:17

标签: android listview progress-bar

我有一个ListView,每个项目包含TextViewProgressBar,使用自定义Adapter填充,如下所示:

String[] actions = new String[] {
        "Stretch", "Walk",
        "Drink water", "Eat fruit(s)" };

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final RoutineArrayAdapter arrayAdapter = 
            new RoutineArrayAdapter(getActivity(), actions);
    setListAdapter(arrayAdapter);     
}

public class RoutineArrayAdapter extends ArrayAdapter<String> {
    private final Context context;
    private final String[] values;

    public RoutineArrayAdapter(Context context, String[] values) {
        super(context, -1, values);
        this.context = context;
        this.values = values;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.routine_list_layout, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.action);
        textView.setText(values[position]);

        return rowView;
    }
}

但每个ProgressBar会有所不同,具体取决于与之关联的文字。

如何以编程方式单独修改每个ProgressBar(大小,颜色,进度值等)?

1 个答案:

答案 0 :(得分:0)

 ProgressBar progressBar = (ProgressBar) rowView.findViewById(R.id.progress_bar);

您可以在getView(..)中获取此progressBar,就像访问textview

一样