ANDROID - RatingBar in ListView example required for send data into MySQL

独自空忆成欢 提交于 2019-12-12 03:03:43

问题


I am just a beginner in programming languages android, my project obtained from internet, and now i got the code to display a value from MySQL and using RatingBar for send the value of ratingbar itself, and i need help how to use it!

can someone explain how to use ratingbar in listview??

i'd create a layout like this :

|------------------|
| 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
|__________________|

and this is a few code i've tried to displayed the ratingbar in listview

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);

My problem is how i know which ratingbar in the list is onTouch?

and sending any rating bar value that was filled from the listview to the server?

i've try to find any tutorial from internet, but the tutorial is so scrimpy


回答1:


Create class that is extended by BaseAdapter then in getView() method identify rating bar and then there you have to set touch listener for rating bar.



来源:https://stackoverflow.com/questions/40829587/android-ratingbar-in-listview-example-required-for-send-data-into-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!