I want to check whether the class being execute or not. Because it didnt give any value on inputName and inputEmail. The value is retrieve from the database.
This is part of the code (SingleSubject.java)
public class SingleSubject extends Activity {
EditText txtName;
EditText txtEmail;
String matrix_id;
// Progress Dialog
private ProgressDialog pDialog;
// JSON parser class
JSONParser jsonParser = new JSONParser();
// single product url
private static final String url_subject_details = "http://192.168.1.12/android_project/get_subject_details.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_STUDENT = "student";
private static final String TAG_MATRIX_ID = "matrix_id";
private static final String TAG_NAME = "name";
private static final String TAG_EMAIL = "email";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_subject);
// getting subject details from intent
Intent i = getIntent();
// getting matrix_id from intent
matrix_id = i.getStringExtra(TAG_MATRIX_ID);
TextView test = (TextView) findViewById(R.id.matrix_id);
test.setText(matrix_id);
// Getting complete matrix_id details in background thread
new GetSubjectDetails().execute();
}
/**
* Background Async Task to Get complete matrix_id details
* */
class GetSubjectDetails extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(SingleSubject.this);
pDialog.setMessage("Loading subject details. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Getting subject details in background thread
* */
protected JSONObject doInBackground(String... args) {
JSONObject json = null;
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("matrix_id", matrix_id));
json = jsonParser.makeHttpRequest(url_subject_details, "GET", params);
}
catch(Exception e)
{
e.printStackTrace();
}
return json;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(JSONObject json) {
super.onPostExecute(json);
// check your log for json response
Log.d("Single Subject Details", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success.equals(1)) {
// successfully received subject details
JSONArray subjectObj = json.getJSONArray(TAG_STUDENT); // JSON Array
// get first subject object from JSON Array
JSONObject subject = subjectObj.getJSONObject(0);
// subject with this matrix_id found
// Edit Text
txtName = (EditText) findViewById(R.id.inputName);
txtEmail = (EditText) findViewById(R.id.inputEmail);
// display subject data in EditText
txtName.setText(subject.getString(TAG_NAME));
txtEmail.setText(subject.getString(TAG_EMAIL));
}
// dismiss the dialog once got all details
pDialog.dismiss();
}
}
}
See Question&Answers more detail:os