这是MainActivity类中的内容
// 评论按钮 comment = (Button) findViewById(R.id.comment); comment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // LayoutInflater inflater = getLayoutInflater(); // final View layout = inflater.inflate(R.layout.comment,(ViewGroup) findViewById(R.id.dialog)); // 获取文本 final EditText inputServer = new EditText(MainActivity.this); // 设置获取文本内容为true inputServer.setFocusable(true); if(MainActivity.CityName == null){ inputServer.setText("你还未搜索当前城市,请定位后再评论"); } AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("评价框").setView(inputServer); builder.setNegativeButton("取消", null); builder.setPositiveButton("确定", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface arg0, int arg1) { String text = inputServer.getText().toString(); if(MainActivity.CityName == null){ HttpGet httpGet = new HttpGet("http://192.168.11.135:8081/MySql/pinlunServlet?cityName=null&comment=" + text); try { HttpResponse response = new DefaultHttpClient().execute(httpGet); if(response.getStatusLine().getStatusCode() < 2000){ Log.i("add", "评论成功"); }else{ Log.e("Err", "评论失败"); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }else{ HttpGet httpGet = new HttpGet("http://192.168.11.135:8081/MySql/pinlunServlet?cityName=" + MainActivity.CityName + "&comment=" + text); try { HttpResponse response = new DefaultHttpClient().execute(httpGet); if(response.getStatusLine().getStatusCode() < 2000){ Log.i("add", "评论成功"); }else{ Log.e("Err", "评论失败"); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } Log.i("add",text); }}); builder.show(); } }); |