问题
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