Android 将用户输入的值传递到url并显示结果
基本上,我正在尝试将用户输入的值传递到url,并根据该url显示结果。。。。因为我没有犯错误,所以我不太确定出了什么问题。非常感谢您的帮助 当我点击按钮时,什么也没发生。。。我添加了eventlistener等Android 将用户输入的值传递到url并显示结果,android,rest,Android,Rest,基本上,我正在尝试将用户输入的值传递到url,并根据该url显示结果。。。。因为我没有犯错误,所以我不太确定出了什么问题。非常感谢您的帮助 当我点击按钮时,什么也没发生。。。我添加了eventlistener等 package com.example.jsonrestclient; import org.json.JSONException; import org.json.JSONObject; import android.os.Bundle; import android.app.Ac
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);
}
}
正如njzk2提到的,您对ET2的评估太早了 您正在onCreate()中执行此操作,这意味着在用户有机会在ET1中键入任何内容之前,ET2已经被分配,因此它将始终为空 您需要做的是移动
ET2=ET1.getText().toString()代码>向下,作为按钮1中的第一行单击
大概button1OnClick
绑定到视图xml中的android:onClick
参数
还有,什么是HttpHandler?从你的进口商品我看不出来。我不确定它是什么,但可能值得考虑将rest调用转移到AsyncTask中。是否在xml中定义了单击按钮?如果是这样,请显示在ET1中写入任何内容之前对代码ET2进行了评估