最近学习服务器端搭建+andriod
1. 客户端简单搭建
实现简单的登录
main.xml 布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:height="20dp"
android:orientation="horizontal"
>
<TextView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/uString"
android:gravity="center_vertical"
android:text="@string/uString"
android:layout_weight="1"
>
</TextView>
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:singleLine="true"
android:layout_weight="5"
/>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:height="20dp"
android:orientation="horizontal"
>
<TextView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/pString"
android:gravity="center_vertical"
android:text="@string/pString"
android:layout_weight="1"
>
</TextView>
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:singleLine="true"
android:password="true"
android:layout_weight="5"
/>
</LinearLayout>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/button"
android:text="点击注册"
android:textSize="10pt"
>
</Button>
</LinearLayout>
主要Activity代码
public class login extends Activity{
/** Called when the activity is first created. */
public Button button;
public EditText username;
public EditText password;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button=(Button) this.findViewById(R.id.button);
username=(EditText)this.findViewById(R.id.username);
password=(EditText)this.findViewById(R.id.password);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String userString=username.getText().toString().trim();
String pwdString=password.getText().toString().trim();
httpUtils.sendPost(userString, pwdString);
}
});
}
httpUtils为发送http请求的工具类,下一讲中会提到