My application can select and show the data into the Log.e but it cannot set it into the textViews. What´s the reason for this?
I want to show the data just after an OnClick event, setting visibility to visible.
final TextView txv_yes = (TextView) findViewById(R.id.vou);
final TextView txv_no = (TextView) findViewById(R.id.nao_vou);
final TextView txv_maybe = (TextView) findViewById(R.id.talvez);
show_count = (RelativeLayout) findViewById(R.id.show_block);
count_vou = (TextView) findViewById(R.id.count_vou);
count_nao = (TextView) findViewById(R.id.count_nao_vou);
count_talvez = (TextView) findViewById(R.id.count_talvez);
txv_yes.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
yes = txv_yes.getText().toString();
new insertYes().execute();
new select().execute();
runOnUiThread(new Runnable() {
public void run() {
setVisible();
}
});
}
});
public class select extends AsyncTask<String, Boolean, Boolean>{
@Override
protected Boolean doInBackground(String... params) {
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("e_id", subString));
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://website.com/includes/select_counter.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
Log.e("pass 1", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 1", e.toString());
Toast.makeText(getApplicationContext(), "Invalid IP Address",
Toast.LENGTH_LONG).show();
}
try
{
BufferedReader reader = new BufferedReader
(new InputStreamReader(inputStream,"UTF-8"));
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
inputStream.close();
result = sb.toString();
Log.e("pass 2", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 2", e.toString());
}
try
{
JSONObject json_data = new JSONObject(result);
get_yes = (json_data.getString("Vou"));
get_no = (json_data.getString("Nao_Vou"));
get_maybe = (json_data.getString("Talvez"));
Log.e("pass 3", "Vou : "+ get_yes);
Log.e("pass 4", "Não Vou : "+ get_no);
Log.e("pass 5", "Talvez: "+ get_maybe);
}
catch(Exception e)
{
Log.e("Fail 3", e.toString());
}
return null;
}
}
public boolean setVisible() {
show_count.setVisibility(View.VISIBLE);
count_vou.setText(get_yes);
count_nao.setText(get_no);
count_talvez.setText(get_yes);
return true;
}
I had this block of code inside the try/catch jus after the Logs.e but the problem was the same:
count_vou.setText(get_yes);
count_nao.setText(get_no);
count_talvez.setText(get_yes);