I have a ListAdapter in my android application… I am trying to add a ratingBar to each item in the list with its value set to a value that is contained in [TAG_RATING]. The problem is that the list is showing and the only ratingBar is being stuck at the very bottom of the list and is rather large.
Please see the below code:
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);
then the ViewBinder class looks like this:
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;
}
}
And the list item xml file looks like this:
<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"
/>
The
RatingBarwidget should be placed in the list row layout that you use in the adapter,R.layout.list_item. Right now, you just placed aRatingBarwidget below theListViewin the main layout.