//在数据库文件
中public void uupdate(String u1, String l1, String m1, String a1,String gotUname) {
// TODO Auto-generated method stub
ContentValues updating = new ContentValues();
updating.put(KEY_FIRSTNAME, u1);
updating.put(KEY_LASTNAME, l1);
updating.put(KEY_MOBILE_NUMBER, m1);
updating.put(KEY_ADDRESS, a1);
ourDatabase.update(DATABASE_TABLE, updating,KEY_FIRSTNAME +"=" +gotUname+"" , null);
}
//用户主文件
package com.example.cabs4u;
import com.example.cabs4u.R;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
public class User_main extends Activity{
EditText uname,lname,mnum,addre;
Button update;
String gotUname;
Main_database get = new Main_database(User_main.this);
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.search_user);
Bundle gotString = getIntent().getExtras();
gotUname=gotString.getString("usrname");
TextView grt;
grt=(TextView) findViewById(R.id.greeting);
grt.setText("Hello "+ gotUname);
uname =(EditText) findViewById(R.id.firstname1);
lname =(EditText) findViewById(R.id.lastname1);
mnum =(EditText) findViewById(R.id.mbnumber1);
addre =(EditText) findViewById(R.id.addr1);
update =(Button)findViewById(R.id.udate);
get.open();
String gusername = get.getuname(gotUname);
String mnmbr = get.mnum(gotUname);
String maddr= get.madd(gotUname);
uname.setText(gotUname);
lname.setText(gusername);
mnum.setText(mnmbr);
addre.setText(maddr);
get.close();
TabHost th;
th = (TabHost) findViewById(R.id.tabhost1);
th.setup();
TabSpec specs = th.newTabSpec("tag1");
specs.setContent(R.id.tab11);
specs.setIndicator(" Find Your Cab ");
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setContent(R.id.tab22);
specs.setIndicator(" Update Profile ");
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setContent(R.id.tab33);
specs.setIndicator(" Other ");
th.addTab(specs);
update.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String u1 = uname.getText().toString();
String l1 = lname.getText().toString();
String m1 = mnum.getText().toString();
String a1 = addre.getText().toString();
if(!(u1.isEmpty() && l1.isEmpty() && m1.isEmpty() && a1.isEmpty()))
{
get.open();
get.uupdate(u1,l1,m1,a1,gotUname);
Dialog d = new Dialog(User_main.this);
d.setTitle(gotUname + "You updated your profile");
d.show();
get.close();
}
}
});
}
}
答案 0 :(得分:0)
字符串文字需要'quoted'
,甚至更好,参数化如下:
ourDatabase.update(DATABASE_TABLE, updating,KEY_FIRSTNAME +"=?", new String[] { gotUname });