本文介绍了ANDROID-将数据发送到MySQL所需的ListView示例中的RatingBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是android编程语言的初学者,我的项目是从互联网获得的,现在我得到了显示MySQL中的值并使用RatingBar来发送ratingbar本身的值的代码,而我需要帮助如何使用它!

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!

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

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

这是我尝试在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);

我的问题是我如何知道列表中的哪个评分栏是onTouch?

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

并将从listview填充的任何等级栏值发送到服务器?

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

推荐答案

创建由BaseAdapter扩展的类,然后在getView()方法中标识等级栏,然后在其中设置等级栏的触摸监听器.

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.

这篇关于ANDROID-将数据发送到MySQL所需的ListView示例中的RatingBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 04:34