title: android required example for using ratingbar in listview
body: <p>I am learning android and want a sample code or an example for using ratingbar just to display  ratings and no onclick events within a listview.</p>
  
  <p>I am fetching the data from a mysql database using json. the same data after being converted into float must be displayed in ratingbar within the list. I tried out many examples here on stackoverflow but most of them seem incomplete.</p>
  
  <p>Thank You</p>
  
  <p>EDIT:  </p>
  
  <p>Following is the code which m using to display string values in the list</p>
  
  <pre><code>public class ReadReviewActivity extends ListActivity {
  
      // Progress Dialog
      private ProgressDialog pDialog;
      String pid;
      String ratings1;
  
      // Creating JSON Parser object
      JSONParser jParser = new JSONParser();
  
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; productsList;
  
      // url to get all products list
      private static String url_all_products = "http://10.0.2.2/hm_andro/get_reviews.php";
  
      // JSON Node names
      private static final String TAG_SUCCESS = "success";
      private static final String TAG_PRODUCTS = "products";
      private static final String TAG_PID = "id";
      private static final String TAG_NAME = "name";
      private static final String TAG_COMMENTS = "comments";
      private static final String TAG_RATINGS = "ratings";
      private static final String TAG_PIDD = "pid";
      private static final String TAG_DATE = "createddate";
  
  
      // products JSONArray
      JSONArray products = null;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.rev);
  
          // Hashmap for ListView
          productsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          // Loading products in Background Thread
          new LoadAllProducts().execute();
  
          Intent i = getIntent();
          pid = i.getStringExtra(TAG_PIDD);
  
  
          // Get listview
          ListView lv = getListView();
  
          // on seleting single product
          // launching Edit Product Screen
          lv.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                      int position, long id) {
  
                  // Starting new intent
                  Intent in = new Intent(getApplicationContext(),
                          MainActivity.class);
                  // sending pid to next activity
  
                  // starting new activity and expecting some response back
                  startActivityForResult(in, 100);
              }
          });
  
      }
  
      // Response from Edit Product Activity
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          // if result code 100
          if (resultCode == 100) {
              // if result code 100 is received 
              // means user edited/deleted product
              // reload this screen again
              Intent intent = getIntent();
              finish();
              startActivity(intent);
          }
  
      }
  
      /**
       * Background Async Task to Load all product by making HTTP Request
       * */
      class LoadAllProducts extends AsyncTask&lt;String, String, String&gt; {
  
          /**
           * Before starting background thread Show Progress Dialog
           * */
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              pDialog = new ProgressDialog(ReadReviewActivity.this);
              pDialog.setMessage("Loading products. Please wait...");
              pDialog.setIndeterminate(false);
              pDialog.setCancelable(false);
              pDialog.show();
          }
  
          /**
           * getting All products from url
           * */
          protected String doInBackground(String... args) {
              // Building Parameters
              List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
              params.add(new BasicNameValuePair("pidd", pid));
              // getting JSON string from URL
              //params.add(new BasicNameValuePair("pid", "745"));
              JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
  
              // Check your log cat for JSON response
              Log.d("All Products: ", json.toString());
  
              try {
                  // Checking for SUCCESS TAG
                  int success = json.getInt(TAG_SUCCESS);
  
                  if (success == 1) {
                      // products found
                      // Getting Array of Products
                      products = json.getJSONArray(TAG_PRODUCTS);
  
                      // looping through All Products
                      for (int i = 0; i &lt; products.length(); i++) {
                          JSONObject c = products.getJSONObject(i);
  
  
                          // Storing each json item in variable
                          String id = c.getString(TAG_PID);
                          String name = c.getString(TAG_NAME);
                           String comments = c.getString(TAG_COMMENTS);
                           String cdate = c.getString(TAG_DATE);
                      String rati = c.getString(TAG_RATINGS);
  
                      String rate1 [] = rati.split(",");
                      ratings1 = rate1[0];
  
  
                          // creating new HashMap
                          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
                          // adding each child node to HashMap key =&gt; value
                          map.put(TAG_PID, id);
                          map.put(TAG_NAME, name);
                      map.put(TAG_COMMENTS, comments);
                      map.put(TAG_DATE, cdate);
                      map.put(TAG_RATINGS,ratings1);
  
                          // adding HashList to ArrayList
                          productsList.add(map);
  
                      }
                  } else {
  
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
  
              return null;
          }
  
          /**
           * After completing background task Dismiss the progress dialog
           * **/
          protected void onPostExecute(String file_url) {
              // dismiss the dialog after getting all products
              pDialog.dismiss();
              // updating UI from Background Thread
              runOnUiThread(new Runnable() {
                  public void run() {
                      /**
                       * Updating parsed JSON data into ListView
                       * */
                      ListAdapter adapter = new SimpleAdapter(
                              ReadReviewActivity.this, productsList,
                              R.layout.review_list, new String[] {TAG_NAME, TAG_COMMENTS, TAG_DATE},
                              new int[] {R.id.revname, R.id.revcomments, R.id.reviewdate});
                      // updating listview
  
                      setListAdapter(adapter);
                  }
              });
  
          }
  
  
      }
      }
  </code></pre>
  
  <p>the xml file :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background="@color/white"
      android:orientation="vertical"
      android:visibility="visible" &gt;
  
      &lt;TextView
          android:id="@+id/pid"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:visibility="gone" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:paddingLeft="6dip"
          android:paddingTop="6dip"
          android:text="Reviewed by:"
          android:textColor="@color/blueish"
          android:textSize="15sp"
          android:visibility="visible" /&gt;
  
      &lt;TextView
          android:id="@+id/revname"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:paddingLeft="6dip"
          android:paddingTop="6dip"
          android:textColor="@color/magenta"
          android:textSize="17sp" /&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Overall Ratings:   "
          android:paddingLeft="6dip"
          android:textColor="@color/blueish"
          android:textSize="11sp" /&gt;
  
          &lt;TextView
              android:id="@+id/textView2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              android:layout_below="@+id/textView1"
              android:text="Service/Hospitality:   "
              android:paddingLeft="6dip"
              android:textColor="@color/blueish"
              android:textSize="11sp" /&gt;
  
          &lt;TextView
              android:id="@+id/textView3"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              android:layout_below="@+id/textView2"
              android:paddingLeft="6dip"
              android:text="Clinical Treatment:   "
              android:textColor="@color/blueish"
              android:textSize="11sp" /&gt;
  
          &lt;TextView
              android:id="@+id/textView4"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              android:layout_below="@+id/textView3"
              android:paddingLeft="6dip"
              android:text="Infrastructure:   "
              android:textColor="@color/blueish"
              android:textSize="11sp" /&gt;
  
          &lt;TextView
              android:id="@+id/textView5"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              android:paddingLeft="6dip"
              android:layout_below="@+id/textView4"
              android:text="Value for Money:   "
              android:textColor="@color/blueish"
              android:textSize="11sp" /&gt;
  
          &lt;RatingBar
              android:id="@+id/Bar1"
              style="?android:attr/ratingBarStyleSmall"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignBottom="@+id/textView1"
              android:layout_toRightOf="@+id/textView1" /&gt;
  
          &lt;RatingBar
              android:id="@+id/Bar2"
              style="?android:attr/ratingBarStyleSmall"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignBottom="@+id/textView2"
              android:layout_toRightOf="@+id/textView2" /&gt;
  
          &lt;RatingBar
              android:id="@+id/Bar3"
              style="?android:attr/ratingBarStyleSmall"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignBottom="@+id/textView3"
              android:layout_toRightOf="@+id/textView3" /&gt;
  
          &lt;RatingBar
              android:id="@+id/Bar4"
              style="?android:attr/ratingBarStyleSmall"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignBottom="@+id/textView4"
              android:layout_toRightOf="@+id/textView4" /&gt;
  
          &lt;RatingBar
              android:id="@+id/Bar5"
              style="?android:attr/ratingBarStyleSmall"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignBottom="@+id/textView5"
              android:layout_toRightOf="@+id/textView5" /&gt;
  
      &lt;/RelativeLayout&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:paddingLeft="6dip"
          android:paddingTop="6dip"
          android:text="Comments:"
          android:textColor="@color/blueish"
          android:textSize="15sp"
          android:visibility="visible" /&gt;
  
      &lt;TextView
          android:id="@+id/revcomments"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:paddingLeft="6dip"
          android:paddingTop="6dip"
          android:textColor="@color/magenta"
          android:textSize="17sp" /&gt;
  
      &lt;TextView
          android:id="@+id/reviewon"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Created On :"
          android:textColor="@color/blueish" /&gt;
  
      &lt;TextView
          android:id="@+id/reviewdate"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="TextView"
          android:textColor="@color/magenta" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>