示例#1
0
  @SuppressLint({"NewApi", "NewApi", "NewApi", "NewApi", "NewApi", "NewApi"})
  public void onCreate(Bundle savedInstanceState) {

    StrictMode.setThreadPolicy(
        new StrictMode.ThreadPolicy.Builder()
            .detectDiskReads()
            .detectDiskWrites()
            .detectNetwork()
            .penaltyLog()
            .build());

    super.onCreate(savedInstanceState);

    setContentView(R.layout.viewinbox);
    TextView tview = (TextView) findViewById(R.id.loginlabel);
    TextView tview1 = (TextView) findViewById(R.id.answerlabel);
    TextView tview2 = (TextView) findViewById(R.id.answerlabel1);
    EditText editview = (EditText) findViewById(R.id.answerfield);
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      question = extras.getString("new_variable_name");
      question1 = extras.getString("new_variable_name1");
      tview.setText(question);
      // tview1.setText(question1);
    }

    // questions = (EditText)findViewById(R.id.answerfield);

    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();

    // define the parameter

    postParameters.add(new BasicNameValuePair("name", question));

    postParameters.add(new BasicNameValuePair("question", question1));

    String response = null;

    // call executeHttpPost method passing necessary parameters

    try {

      response =
          CustomHttpClient.executeHttpPost(

              // "http://129.107.187.135/CSE5324/jsonscript.php", // your ip address if using
              // localhost server

              "http://10.0.2.2/sathesh/viewanswer.php", // in case of a remote server
              postParameters);

      // store the result returned by PHP script that runs MySQL query

      String result = response.toString();

      // parse json data

      try {

        returnString = "";

        JSONArray jArray = new JSONArray(result);

        for (int i = 0; i < jArray.length(); i++) {

          JSONObject json_data = jArray.getJSONObject(i);

          Log.i(
              "log_tag",
              ", loginemail: "
                  + json_data.getString("loginemail")
                  + ",answers: "
                  + json_data.getString("answers"));

          // Get an output to the screen

          returnString = json_data.getString("answers");
          // returnString1 = json_data.getString("answers");

          loginemail = json_data.getString("loginemail");
          // content.add(returnString);
          // tview1.setText(returnString);
          // int j=1;

          test = "No";
          name =
              name
                  + returnString
                  + "\n"
                  + "\n"
                  + "\t"
                  + "\t"
                  + "\t"
                  + "\t"
                  + "\t"
                  + "Answered By"
                  + "\n"
                  + "\t"
                  + "\t"
                  + "\t"
                  + "\t"
                  + "\t"
                  + "\t"
                  + "\t"
                  + "\t"
                  + "\t"
                  + "\t"
                  + loginemail
                  + "\n"
                  + "------------------"
                  + "\n"
                  + "\n";
        }
        // name="No Answer For This Question";

        // tview1.setText(name);
        // tview2.setText(loginemail);

        if (name != "") {
          editview.setText(name);
        }

        if (test == "") {
          test = "No";
          editview.setText(test);
        }

      } catch (JSONException e) {

        Log.e("log_tag", "Error parsing data " + e.toString());

      } catch (Exception e) {

        Log.e("log_tag", "Error in Display!" + e.toString());
        ;
      }

    } catch (Exception e) {

      Log.e("log_tag", "Error in http connection!!" + e.toString());
    }
  }