Итак, я хочу увеличить текст TextView, который показывает данные из кода JSON.Increment TextView с нажатием кнопки и JSON
package com.example.kane.bibliokane;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.io.IOException;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.net.HttpURLConnection;
import static android.R.attr.data;
public class ListesLivres extends AppCompatActivity {
TextView Titre, Auteur, Categorie , Editeur , Prix;
int score = 0;
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listeslivres);
Titre = (TextView) findViewById(R.id.textView16);
Auteur = (TextView) findViewById(R.id.textView17);
Categorie = (TextView) findViewById(R.id.textView18);
Editeur = (TextView) findViewById(R.id.textView19);
Prix = (TextView) findViewById(R.id.textView20);
b1 = (Button)findViewById(R.id.button4);
b2 = (Button)findViewById(R.id.button3);
new getData().execute();
}
class getData extends AsyncTask<String, String, String> {
HttpURLConnection urlConnection;
@Override
protected String doInBackground(String... args) {
StringBuilder result = new StringBuilder();
try {
URL url = new URL("http://192.168.43.13:8000/api/liste.json");
urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
urlConnection.disconnect();
}
return result.toString();
}
@Override
protected void onPostExecute(String result) {
try {
JSONArray jsonArray = new JSONArray(result);
JSONObject jsonObject = jsonArray.getJSONObject(0);
String t = jsonObject.getString("titre");
String a = jsonObject.getString("auteur");
String c = jsonObject.getString("categorie");
String e = jsonObject.getString("editeur");
String p = jsonObject.getString("prix");
Titre.setText(t);
Auteur.setText(a);
Categorie.setText(c);
Editeur.setText(e);
Prix.setText(p);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Я видел, как приращение TextView с помощью кнопки в этой теме: Increment TextView with button click
Но я не знаю, как адаптировать его с моим кодом, так как я хочу, чтобы программа, чтобы показать первый, из ДАННЫЕ jsonObject (0), то, если я нажимаю кнопку (b1), он увеличивает ++, а в другой кнопке (b2) уменьшается до достижения 0.
Благодаря