2016-11-27 48 views
0

我只是一個初學者,使用編程語言android,我的項目從互聯網獲得,現在我得到的代碼顯示值爲MySQL,使用RatingBar發送值ratingbar本身,我需要幫助如何使用它!ANDROID - ListView中的RatingBar示例將數據發送到MySQL所需的示例

有人可以解釋如何在listview中使用ratingbar ??

我想創建這樣一個佈局:

|------------------| 
| TextView   | ---> Questionare question obtained from server (id 1) 
| * * * * *  | ---> Rating Bar the value 
|------------------| 
| TextView   | ---> Questionare question obtained from server (id 2) 
| * * * * *  | ---> Rating Bar the value 
|------------------| 
| TextView   | ---> Questionare question obtained from server (id 3) 
| * * * * *  | ---> Rating Bar the value 
|__________________| 

,這是幾碼我試圖顯示ratingbarlistview

AsyncTask doInBackground

HttpHandler sh = new HttpHandler(); 
      String url = "http://****.com/send_data.php"; 
      String jsonStr = sh.makeServiceCall(url); 

      Log.e(TAG, "Response from url: " + jsonStr); 

      if (jsonStr != null) { 
       try { 
        JSONArray jsonObj = new JSONArray(jsonStr); 
        for (int i = 0; i < jsonObj.length(); i++) { 
         JSONObject c = jsonObj.getJSONObject(i); 

         String id = c.getString("id"); 
         String ask = c.getString("ask"); 

         HashMap<String, String> pertanyaans = new HashMap<>(); 

         pertanyaans.put("id", id); 
         pertanyaans.put("ask", ask); 

         contactList.add(pertanyaans); 
        } 
       } catch (final JSONException e) { 
        Log.e(TAG, "Json parsing error: " + e.getMessage()); 
        runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 
          Toast.makeText(getApplicationContext(), 
            "Json parsing error: " + e.getMessage(), 
            Toast.LENGTH_LONG) 
            .show(); 
         } 
        }); 

       } 
      } else { 
       Log.e(TAG, "Couldn't get json from server."); 
       runOnUiThread(new Runnable() { 
        @Override 
        public void run() { 
         Toast.makeText(getApplicationContext(), 
           "Couldn't get json from server. Check LogCat for possible errors!", 
           Toast.LENGTH_LONG) 
           .show(); 
        } 
       }); 

      } 

      return null; 
     } 
     @Override 
     protected void onPostExecute(Void result) { 
      super.onPostExecute(result) 
      if (pDialog.isShowing()) 
       pDialog.dismiss(); 
      ListAdapter adapter = new SimpleAdapter(
        Pertanyaan.this, contactList, 
        R.layout.list_pertanyaan, new String[]{"ask", "id"}, new int[]{R.id.ask, R.id.txtid}); 

      lv.setAdapter(adapter); 

我的問題是我怎麼知道哪個的RatingBar列表是onTouch

併發送從listview填充到服務器的任何評級欄值?

我一直試圖找到從互聯網上的任何教程,但教程是如此scrimpy

回答

0

創建由BaseAdapter延伸則在getView()類方法鑑定等級欄,然後有你必須設置評分欄的觸摸監聽器。