帮我写个Android应用程序行吗,选修课的作业还真不会做
能不能帮我做一个Android应用程序,程序有四点要求:1, 有控件,至少一个事件监听器,可以更新后台图片2,有后台服务线程3,内部文件,往里面写数据,能读出来4,tabhost
我邮箱是254457234@qq.com
只有自己做了才会变成自己的
[解决办法]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/imgLogoLogin"
android:src="@drawable/logo"/>
<TextView
android:id="@+id/lblTempLogin1"
android:layout_below="@id/imgLogoLogin"
android:layout_width="fill_parent"
android:layout_height="15dip"/>
<TextView
android:text="用户名:"
android:id="@+id/lblUserNameLogin"
android:textStyle="bold"
android:layout_below="@id/lblTempLogin1"
android:layout_width="63dip"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/txtUserNameLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/lblUserNameLogin"
android:layout_alignBottom="@id/lblUserNameLogin"
android:background="@android:drawable/editbox_background"/>
<TextView
android:id="@+id/lblTempLogin2"
android:layout_below="@id/txtUserNameLogin"
android:layout_width="fill_parent"
android:layout_height="15dip"/>
<TextView
android:text="密 码:"
android:id="@+id/lblPasswordLogin"
android:textStyle="bold"
android:layout_below="@id/lblTempLogin2"
android:layout_width="63dip"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/txtPasswordLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
android:layout_toRightOf="@id/lblPasswordLogin"
android:layout_alignBottom="@id/lblPasswordLogin"
android:background="@android:drawable/editbox_background"/>
<CheckBox
android:id="@+id/ckbMemorizeLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtPasswordLogin"
android:text="记住密码" />
<Button
android:id="@+id/btnLoginLogin"
android:layout_below="@id/ckbMemorizeLogin"
android:layout_width="63dip"
android:layout_height="27dip"
android:background="@drawable/button"
android:textSize="13dip"
android:text="登 录"/>
<TextView
android:id="@+id/lblTempLogin3"
android:layout_below="@id/btnLoginLogin"
android:layout_width="10dip"
android:layout_height="27dip"
android:layout_toRightOf="@id/btnLoginLogin"
android:layout_alignBottom="@id/btnLoginLogin"/>
<Button
android:id="@+id/btnExitLogin"
android:layout_width="63dip"
android:layout_height="27dip"
android:background="@drawable/button"
android:textSize="13dip"
android:layout_toRightOf="@id/lblTempLogin3"
android:layout_alignBottom="@id/lblTempLogin3"
android:text="退 出"/>
</RelativeLayout>
/**
* 登录界面
* @version 1.0
*/
public class LoginAct extends CoreActivity {
private EditText txtUserName = null;
private EditText txtPassword = null;
private CheckBox ckbMemorize = null;
private Button btnLogin = null;
private String contextRoot = "", fileName = "memorize.txt";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_act);
DecoApp.getBean().addActivity(this);
setTitle("用户登录");
txtUserName = (EditText) findViewById(R.id.txtUserNameLogin);
txtPassword = (EditText) findViewById(R.id.txtPasswordLogin);
ckbMemorize = (CheckBox) findViewById(R.id.ckbMemorizeLogin);
btnLogin = (Button) findViewById(R.id.btnLoginLogin);
contextRoot = file.getContextRoot(this);
setLoginClick();
((Button) findViewById(R.id.btnExitLogin)).setOnClickListener(getExitClick());
setUserInfo();
}
private void setLoginClick() {
btnLogin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String userName = txtUserName.getText().toString();
String password = txtPassword.getText().toString();
if (checkNull(userName, "用户名", true) && checkNull(password, "密码", true)) {
try {
String param = "loginName=" + userName + "&password=" + password;
String json = tool.getSoundCode(Globe.ROOT_URL + "/login/doLogin.php", param);
JSONObject object = new JSONObject(json);
if (object.getBoolean("result")) {
JSONObject object1 = object.getJSONObject("user");
Globe.user.setId(object1.getLong("id"));
Globe.user.setRealName(object1.getString("realName"));
Globe.user.setUserCode(object1.getString("userCode"));
Globe.user.setMenuTree(object.getJSONObject("menu"));
Globe.setMenuSet();
file.deleteFolder(contextRoot + fileName);
file.createTxt(contextRoot, fileName);
if (ckbMemorize.isChecked()) {
file.write(contextRoot + fileName, "{userName:"" + userName + "",password:"" + password + ""}");
}
startActivity(getIntent(IndexAct.class));
} else {
alert(R.drawable.err, object.getString("message"), null);
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
});
}
private void setUserInfo() {
try {
String json = file.readFile(contextRoot + fileName);
if (!"".equals(json)) {
JSONObject object = new JSONObject(json);
txtUserName.setText(object.getString("userName"));
txtPassword.setText(object.getString("password"));
ckbMemorize.setChecked(true);
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}