android - 如何在android中显示评分栏?

标签 android rating

成功解析JSON并显示在listview中。
在 ListView 中,我显示了名称、城镇和评级,这些值已经存储在数据库中。 我想在那里显示评级栏而不是评级编号。 此外,它不应支持任何用户交互,我的意思是我只想显示评级栏以供引用。
我该怎么做??
帮助!!

        // Getting Array of Root
        root = json.getJSONArray(TAG_ROOT);

        // looping through All root
        for (int i = 0; i < root.length(); i++) {
            JSONObject c = root.getJSONObject(i);

            // Storing each json item in variable

            String name = c.getString(TAG_NAME);
            String town = c.getString(TAG_TOWN);
            String totalRating = c.getString(TAG_RATING);

            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();



                // adding each child node to HashMap key => value

                map.put(TAG_NAME, "Name: " + name);
                map.put(TAG_TOWN, "Town: " + town);
                map.put(TAG_RATING, "Rating: " + totalRating);

                // adding HashList to ArrayList
                myList.add(map);

        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    /**
     * Updating parsed JSON data into ListView
     * */
    ListAdapter adapter = new SimpleAdapter(this, myList,
            R.layout.list_item, new String[] { TAG_NAME, TAG_TOWN,
                    TAG_RATING }, new int[] { R.id.name, R.id.address,
                    R.id.rating });

    setListAdapter(adapter);

list_item.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/name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="2dip"
    android:paddingTop="6dip"
    android:textColor="#006fa8"
    android:textSize="16sp"
    android:textStyle="bold" />


   <TextView
    android:id="@+id/address"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="2dip"
    android:textColor="#acacac" >
   </TextView>

   <TextView
    android:id="@+id/rating"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="2dip"
    android:textColor="#acacac" >
 </TextView>  

 </LinearLayout>

最佳答案

你好检查下面的代码

<RatingBar 
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:isIndicator="true"
    android:numStars="5"
    android:stepSize="1"
    android:rating="5"
    android:id="@+id/pop_ratingbar"
    style="?android:attr/ratingBarStyleSmall"
/>

RatingBar ratingBar = (RatingBar) findviewbyid(R.id.pop_ratingbar);
ratingBar.setRating(4.0f); 

关于android - 如何在android中显示评分栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9941244/

相关文章:

java - Retrofit2 发送 POST 请求

android - greenDAO:比较两个属性

Android、Skia 和硬件加速图形

android - Android 应用程序的版本控制如何工作?

php - ELO评级算法的实现

rating - Android RatingBar numStart 不起作用

mysql - 需要Mysql评级和排名教程

android - ivona tts 以及如何以编程方式获取所有已安装语音的列表?

mysql - "IF"语句 MySQL

javascript - jQuery 星星评级消息反射(reflect)在所有项目上