2013-03-13 146 views
0

基本上我試圖將用戶輸入的值傳遞給一個url並顯示基於該結果的結果....作爲即時通訊沒有錯誤我不太確定什麼錯誤。任何幫助是極大的讚賞將用戶輸入的值傳遞給url並顯示結果

當我上的按鈕沒有任何反應單擊......我有事件偵聽增加等

package com.example.jsonrestclient; 

import org.json.JSONException; 
import org.json.JSONObject; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.view.View; 
import android.widget.TextView; 
import android.widget.EditText; 

public class MainActivity extends Activity { 

protected TextView tv1; 
protected TextView tv2; 
protected TextView tv3; 
protected TextView tv4; 
protected EditText ET1; 
protected String ET2; 



@Override 
    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     tv1 = (TextView) findViewById(R.id.textView1); 
     tv2 = (TextView) findViewById(R.id.textView2); 
     tv3 = (TextView) findViewById(R.id.textView3); 
     tv4 = (TextView) findViewById(R.id.textView4); 
     ET1 = (EditText) findViewById(R.id.editText1); 
     ET2 = ET1.getText().toString(); 
    } 

    public void button1OnClick(View v) { 
     String patientString = HttpHandler.HttpGetExec(HttpHandler.baseURI + ET2); 

     String patientFName = "NOT FOUND", 
       patientLName = "NOT FOUND", 
       DOB = "NOT FOUND", 
       patientGender = "NOT FOUND", 
       hospitalNumber = "NOT FOUND"; 
     JSONObject patientObj = null; 

     try { 
      patientObj = new JSONObject(patientString); 
      patientFName = (String) patientObj.get("PatientFName"); 
      patientLName = (String) patientObj.get("PatientLName"); 
      DOB = (String) patientObj.get("DOB"); 
      patientGender = (String) patientObj.get("PatientGender"); 
      hospitalNumber = (String) patientObj.get("HospitalNumber"); 
     } catch (JSONException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     tv1.setText(patientFName + " " + patientLName); 
     tv2.setText("DOB" + " " + DOB); 
     tv3.setText("Gender" + " " + patientGender); 
     tv4.setText("Hospital" + " " + hospitalNumber); 

    } 
} 
+0

是你在xml中定義的按鈕的onClick?如果是,則顯示代碼 – 2013-03-13 14:03:55

+1

ET2在ET1中寫入任何內容之前進行評估 – njzk2 2013-03-13 14:19:49

回答

0

由於njzk2提到,你還爲時過早評估ET2。

你在onCreate()中這樣做,這意味着在用戶有機會在ET1中輸入任何內容之前ET2已經被分配,所以它總是空的。

你需要做的是將ET2 = ET1.getText().toString();下移,作爲button1OnClick的第一行。

推測button1OnClick綁定到你的視圖xml中的參數?

另外,什麼是HttpHandler?我無法從您的進口中知道。我不確定它是什麼,但它可能是值得考慮的其餘呼籲轉移到一個AsyncTask。