0

AndroidアプリケーションにListAdapterがあります...リスト内の各アイテムにratingBarを追加しようとしていますが、その値は[TAG_RATING]に含まれている値に設定されています。問題は、リストが表示されており、ratingBarのみがリストの一番下に表示されており、かなり大きいことです。

以下のコードを参照してください。

   ListAdapter adapter = new SimpleAdapter(
                        AllProductsActivity.this, productList,
                        R.layout.list_item, new String[] { TAG_BID,
                                TAG_NAME,
                                TAG_RATING},
                        new int[] { R.id.pid, R.id.name, R.id.ratingBar});
                    ((SimpleAdapter) adapter).setViewBinder(new MyBinder());
                // updating listview
                setListAdapter(adapter);

その場合、ViewBinderクラスは次のようになります。

   class MyBinder implements ViewBinder{
    public boolean setViewValue(View view, Object data, String textRepresentation) {
        if(view.getId() == R.id.ratingBar){
            String stringval = (String) data;
            float ratingValue = Float.parseFloat(stringval);
            RatingBar ratingBar = (RatingBar) view;
            ratingBar.setRating(ratingValue);
            return true;
        }
        return false;
    }
}

また、リストアイテムのxmlファイルは次のようになります。

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >


<TextView
    android:id="@+id/pid"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:visibility="gone" />

<!-- Name Label -->
<TextView
    android:id="@+id/name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingTop="6dip"
    android:paddingLeft="6dip"
    android:textSize="17dip"
    android:textStyle="bold" />

  <RatingBar
    android:id="@+id/rating"
    style="?android:attr/ratingBarStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="6dip"
    android:stepSize="0.25"
    android:numStars="5"
    />

4

1 に答える 1

1

ウィジェットはRatingBar、アダプタで使用するリスト行レイアウトに配置する必要がありますR.layout.list_item。今のところ、メインレイアウトののRatingBar下にウィジェットを配置しました。ListView

于 2012-10-24T03:20:27.803 に答える