这是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();
}
});
|
这是comment.xml中的配置
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:background="#ffffffff" android:orientation="horizontal"
android:id="@+id/dialog">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/tvname"
android:text="评论:" />
<EditText
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/etname"
android:minWidth="100dip"/>
</LinearLayout>
AndroidManifest.xml中权限(仅供参考,如有缺少可以添加)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.baudumap"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="18" >
</uses-sdk>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.baudumap" >
</instrumentation>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
</uses-permission>
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" >
</uses-permission>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" >
</uses-permission>
<uses-permission android:name="android.permission.READ_LOGS" >
</uses-permission>
<application
android:allowBackup="true"
android:icon="@drawable/wing"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="android.test.runner" />
<activity
android:name="com.example.baudumap.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="com.baidu.location.f"
android:enabled="true"
android:process=":remote" >
</service>
</application>
</manifest>
|
最新内容请见作者的GitHub页:http://qaseven.github.io/