如何在android studio上使用简单适配器设置分级栏值
这是我的ActivityJava类,使用vollylibry从服务器获取json数组形式的数据。所以我想从服务器获取评级值,并将其设置为评级栏 ListActivity.java如何在android studio上使用简单适配器设置分级栏值,android,listview,listadapter,ratingbar,simpleadapter,Android,Listview,Listadapter,Ratingbar,Simpleadapter,这是我的ActivityJava类,使用vollylibry从服务器获取json数组形式的数据。所以我想从服务器获取评级值,并将其设置为评级栏 ListActivity.java public void LoadList() { RequestQueue queue = Volley.newRequestQueue(this); String url ="http://beezzserver.com/slthadi/projectPHI/place/index.php?
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();
}
}
public void LoadList(){
RequestQueue=Volley.newRequestQueue(this);
字符串url=”http://beezzserver.com/slthadi/projectPHI/place/index.php?Lid=“+lid+”&gid=“+gid+”&cid=“+cid+”;
JsonArrayRequest=新的JsonArrayRequest(request.Method.GET,url,null,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONArray响应){
设置位置(响应);
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
错误。printStackTrace();
}
});
添加(请求);
}
公共无效设置位置(JSONArray响应){
列表=新的ArrayList();
试一试{
对于(int i=0),根据文档,SimpleAdapter没有填充RADIGINBAR。您必须扩展适配器,并将其填充到您自己的。Opz。谢谢。我会考虑的。
<?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>