I have an app that gets data from a mysql database. I have included the code below. For some reason I am able to set the text of the textview manually but when I try to set it with the use of an if statement to change the category depending on score then it doesnt update the text view. I have no idea why this is
public class Category extends AppCompatActivity{
private TextView game_id;
private TextView team_name;
private TextView scoreTV;
private TextView category;
private Button readyToPlay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_categories);
game_id = (TextView) findViewById(R.id.tvGameID);
game_id.setText(getIntent().getStringExtra("game_id"));
team_name = (TextView) findViewById(R.id.tvGameID);
team_name.setText(getIntent().getStringExtra("team_name"));
scoreTV = (TextView) findViewById(R.id.tvScore);
category = (TextView) findViewById(R.id.tvCategory);
readyToPlay = (Button) findViewById(R.id.rtpButton);
getData();
}
private void getData() {
String teamName = team_name.getText().toString().trim();
if (teamName.equals("")) {
Toast.makeText(this, "Please enter an id", Toast.LENGTH_LONG).show();
return;
}
String url = "http://ift.tt/2wuw1Il"+game_id.getText().toString()+"&& team_name="+ team_name.getText().toString();
StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
showJSON(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Category.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
private void showJSON(String response) {
String score = "";
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray("score");
JSONObject collegeData = result.getJSONObject(0);
score = collegeData.getString("score");
} catch (JSONException e) {
e.printStackTrace();
}
scoreTV.setText(score);
if (score.equals("0")){
category.setText("Object");
}
}
}
Aucun commentaire:
Enregistrer un commentaire