I can not in any way to display the text of the TextView. I have tried in various ways and since it is a static method do I have to call this function:
sendQuery.text.setText(provola);
this is the secondary class:
public class sendQuery extends main {
// ///////// Public method to send Query ///////////
public static String send(String query, Activity sendQuery) {
String result = "0";
InputStream is = null;
String weekDayVal = null;
String provola = null;
// the query to send
ArrayList<NameValuePair> querySend = new ArrayList<NameValuePair>();
querySend.add(new BasicNameValuePair("querySend", query));
// http post
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://locali.altervista.org/php/locali.php");
httppost.setEntity(new UrlEncodedFormEntity(querySend));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
try {
TextView text = (TextView) sendQuery
.findViewById(R.id.textView10);
JSONArray weekDetails = new JSONArray(result); // Your response
// string
for (int index = 0; index < 1/* weekDetails.length() */; index++) {
JSONObject tempWeekDetail = weekDetails
.getJSONObject(index);
weekDayVal = tempWeekDetail.getString("Lunedi");// Value for
// Monday
// added this Log which you can view from LogCat. also
// changed above variable name
Log.i("Resp Value", "Moday Value " + weekDayVal);
JSONObject provino = weekDetails.getJSONObject(index);
provola = provino.getString("Martedi");// Value for Monday
// added this Log which you can view from LogCat. also
// changed above variable name
Log.i("Resp Value", "Moday Value " + provola);
text.setText(provola);
}
} catch (Exception e) {
}
} catch (Exception e) {
Log.e("log_tag", "Error converting result: " + e.toString());
}
Log.i("SendQUERY", result);
return result;
}
}
instead this is the main activity:
public class main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView resLayout = (TextView) findViewById(R.id.res);
String res = sendQuery.send("SELECT * FROM contatti", null);
resLayout.append(res);
}
}
the value in the variable "provola" is present but nothing is displayed. Thanks.