问题描述
这是我的活动java类,并使用Volly libry从服务器获取数据作为json数组。所以我想从服务器获取评分值并将其设置到评分栏。
ListActivity.java
public void LoadList() {
RequestQueue queue = Volley.newRequestQueue(this);
String url ="http://beezzserver.com/slthadi/projectPHI/place/index.PHP?Lid="+lid+"&gid="+gid+"&cid="+cid+"";
JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET,url,null,new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
setPlace(response);
}
},new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printstacktrace();
}
});
queue.add(request);
}
public void setPlace(JSONArray response){
List<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
try {
for(int i=0; i<response.length(); i++){
JSONObject object = response.getJSONObject(i);
HashMap<String,String> map = new HashMap<>();
map.put("id",object.getString("id"));
map.put("name",object.getString("name"));
map.put("rating",object.getString("reating")); //need to set this value to rating bar
map.put("img",Integer.toString(array[i]));
list.add(map);
}
int layout = R.layout.item_placelist;
int[] views = {R.id.pid,R.id.tvName,R.id.rtbPlace}; //this not work
String[] colums = {"id","name","rating"};
SimpleAdapter adapter = new SimpleAdapter(this,list,layout,colums,views);
lv.setAdapter(adapter);
}catch (Exception e){
e.printstacktrace();
}
}
这是我的列表项布局
item_placelist.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="110dp"
android:layout_marginHorizontal="10dp">
.............. other codings.....................
<ratingBar
android:id="@+id/rtbPlace"
style="@style/Widget.AppCompat.ratingBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:progressBackgroundTint="@color/textDark"
android:progresstint="@color/colorGreenSpc"
android:numStars="5"
android:rating="3.5"
android:layout_gravity="end"/>
......................other code...............
</LinearLayout>
如何使用简单适配器设置等级栏的值?我试图使用基于此的一些问题来掩饰这一点。但是我找不到真正的解决方案。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)