代码

来源:互联网 发布:uv在淘宝什么意思 编辑:程序博客网 时间:2024/05/29 08:29
public class OnClickListenerImpl1 implements OnClickListener{public void onClick(View v){if(v == dl){//按下登录按钮String editusername =username.getText().toString();String editpassword = password.getText().toString();if(editusername.trim().equals("")){//当用户名为空时 Toast.makeText(SKA3000.this, "请您输入用户名", Toast.LENGTH_SHORT).show();return;}if(editpassword.trim().equals("")){//当密码为空时Toast.makeText(SKA3000.this, "请您输入密码!", Toast.LENGTH_SHORT).show();return;}//myDialog = ProgressDialog.show(SKA3000.this, "进度", "正在加载...",true);//final ProgressDialog proDia =ProgressDialog.show(SKA3000.this,//"搜索服务器", //对话框显示标题//"请耐心等待");//对话框显示文字new Thread(){  //将耗时的动作放到线程中public void run(){//重写的run方法  Socket s = null;DataOutputStream dout = null;DataInputStream din = null;try{//Thread.sleep(5000);//运行5秒后关闭对话框s = new Socket("192.168.1.101",8888);//指定服务器dout = new DataOutputStream(s.getOutputStream());//打印输出流din = new DataInputStream(s.getInputStream());//BufferedReader buf =new BufferedReader(//new InputStreamReader(client.getInputStream()));//缓冲区读取dout.writeBytes("dl:"+username.getText().toString()+"|"+password.getText().toString()+"|");//发送用户名、密码//Thread.sleep(5000);//等待String msg = din.readLine();//读取返回的数据SKA3000.this.info.setText(din.readLine());if(msg.startsWith("dlfh:")){//收到登录返回信息msg=msg.substring(5);String para[]=msg.split("|");if(para[0]=="1"){Intent it  = new Intent(SKA3000.this,BaiduMapActivity.class);//实例化IntentSKA3000.this.startActivityForResult(it,1);//启动Activity}else if(para[0]=="0"){//登录失败Toast.makeText(SKA3000.this, "用户名或密码错误!", Toast.LENGTH_LONG).show();}}}catch(Exception e){//捕获异常e.printStackTrace();//打印异常}finally {//使用finally保证之后的语句一定被执行try{if(din != null){din.close();din = null;}}catch(Exception e){e.printStackTrace();}try{if(dout != null){dout.close();dout = null;}                                                       }catch(Exception e){e.printStackTrace();}try{if(s != null){s.close();s = null;}                                                       } catch(Exception e){e.printStackTrace();}//myDialog.dismiss();}}}.start();//线程启动}}}西安-防盗定位(258472152) 13:37:32服务器发的数据怎么收不到
原创粉丝点击