qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

关于Button点击弹出输入框,并且通过Servlet连接数据库

 应主管的要求,做了一个月的Android,对Android也发生了许多的问题,下面是主管让我弄的一个弹出输入框,能够输入评论,保存到数据库的功能
  这是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>

posted on 2013-11-12 11:00 顺其自然EVO 阅读(367) 评论(0)  编辑  收藏 所属分类: android


只有注册用户登录后才能发表评论。


网站导航:
 
<2013年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜