0

ListView を作成しました。各リスト項目には進行状況バーが含まれています。このリスト ビューをスクロールすると、すべての進行状況バーが表示され、適切にスクロールされます。ただし、常に一番上に表示される進行状況バーのある最初の項目は除きます。視覚効果は次のとおりです。下にスクロールすると、すべての進行状況バーが適切にスクロールされますが、最初の進行状況バーが最初に表示された固定位置に新しい進行状況バーが常に描画されます。これを取り除く方法を知っている人はいますか?

レイアウトプランナー_main.xml:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="blocksDescendants">

    <include layout="@layout/planner_row"/>

    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <include layout="@layout/parent_view"/>

    <TextView
        android:id="@+id/empty_view"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/no_entries"
        android:textSize="38sp"
        android:visibility="gone"/>

</RelativeLayout>

レイアウト プランナー_row.xml:

    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list_layout"
    android:layout_width="wrap_content"
    android:layout_height="50dp">

    <TextView
        android:id="@+id/category_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:textColor="@color/black"
        android:textSize="18sp">
    </TextView>

    <TextView
        android:id="@+id/category_spent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/category_name"
        android:layout_centerVertical="true"
        android:textColor="@color/black"
        android:textSize="18sp" >
    </TextView>

    <ProgressBar
        android:id="@+id/category_bar"
        android:layout_width="200dp"
        android:layout_height="15dp"
        android:layout_below="@id/category_name"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:max="100" />

    <TextView
        android:id="@+id/category_limit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/category_bar"
        android:layout_below="@id/category_spent"
        android:layout_centerVertical="true"
        android:textColor="@color/black"
        android:textSize="18sp" >
    </TextView>

</RelativeLayout>

アダプターの主要部分:

public class PlannerListAdapter extends SimpleCursorAdapter {

    ...

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final PlannerViewHolder holder;
        // create a new row view
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.planner_row, parent, false);
            // find children views
            TextView tvName = (TextView) convertView.findViewById(R.id.category_name);
            TextView tvLimit = (TextView) convertView.findViewById(R.id.category_limit);
            TextView tvSpent = (TextView) convertView.findViewById(R.id.category_spent);
            ProgressBar bar = (ProgressBar) convertView.findViewById(R.id.category_bar);

            holder = new PlannerViewHolder(tvName, tvLimit, tvSpent, bar);

            // tag the row with it's children views
            convertView.setTag(holder);
        } else { // reuse existing row view
            holder = (PlannerViewHolder)convertView.getTag();
        }

        if (dataCursor.moveToPosition(position)) {
            holder.tvCategory.setText(dataCursor.getString(1));
            holder.bar.setProgress(50);
        }

        return convertView;
    }

    ...

    public static class PlannerViewHolder {

        private ProgressBar bar;
        private TextView tvCategory, tvLimit, tvSpent;

        public PlannerViewHolder(TextView tv1, TextView tv2, TextView tv3, ProgressBar b) {
            tvCategory = tv1;
            tvLimit = tv2;
            tvSpent = tv3;
            bar = b;
        }
    }

}

アダプタを使用するアクティビティのコード:

@Override
public void onCreate(Bundle savedInstanceState) {
    setLayout(R.layout.planner_main);
    super.onCreate(savedInstanceState);
    ...
    listView = (ListView)findViewById(android.R.id.list);
    Cursor c = db.getCategoriesData();
    adapter = new PlannerListAdapter(context, c, new String[] { Data.Categories.NAME, Data.Categories.LIMIT }, new int[] { R.id.category_name, R.id.category_limit });
    listView.setAdapter(adapter);
4

0 に答える 0