关于,我从一个php网页得到一个指令,得到之后进行if判断根据指令输出不同文字
public class MainActivity extends Activity {
// 以线程的方式发起一个请求
//
TextView myTextView = null, myTextView3 = null;
//
Button btn1, btn2, btn3;
//
ImageView myImageView;
//
URL myUrl;
//
HttpURLConnection myHttpURLConnection;
//
InputStream myInputStream;
//
String strResult = "";
//
ByteArrayOutputStream myByteArrayOutputStream;
//
Handler handler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == 1) {
Bundle b = msg.getData();
String str = b.getString("value");
myTextView3.setText(str);
}
if(msg.what==2){
}
if(msg.what==3){
}
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 实例化组件
// myTextView = (TextView) this.findViewById(R.id.txtInfo);
//
myImageView = (ImageView) this.findViewById(R.id.imageView1);
//
btn1 = (Button) this.findViewById(R.id.button1);
//
// btn2 = (Button) this.findViewById(R.id.button2);
//
// btn3 = (Button) this.findViewById(R.id.button3);
//
myTextView3 = (TextView) this.findViewById(R.id.mytext);
//
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//
new class1().start();
}
});
//
// btn2.setOnClickListener(new OnClickListener() {
//
// @Override
// public void onClick(View v) {
// //
// new class2().start();
// }
// });
//
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
class class1 extends Thread {
@Override
public void run() {
// TODO Auto-generated method stub
try {
//
myUrl = new URL("http://10.doordemo1.sinaapp.com/index.php");
//
byte[] buff = WebUtill.getContent(myUrl, "GET", "utf-8");
String strResult = new String(buff);
Bundle data = new Bundle();
data.putString("value", strResult);
Message msg = new Message();
msg.what = 1;
msg.setData(data);
handler.sendMessage(msg);
// 直接输出内容
// myTextView3.setText("开锁成功!");
//String a="1";
//String b="0";
if(strResult.equals("1"))
{myTextView3.setText("开锁成功!");}
else
{myTextView3.setText("开锁失败!");}
// System.out.println(strResult);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
//
WebUtill.closeConnection();
}
}
}
可是为什么我点击button之后没有反应啊?是不是判断语句错了啊???求解救啊 ,这个问题我纠结了一晚上了!!!