0

问题:我想将我的共享首选项数据永久保存到 sqLite 数据库中。我在这里提供了我的代码,它将我的数据存储到共享首选项文件夹中,但是当我尝试存储新数据时,前一个数据会破坏...... ....是否有任何解决方案可以将数据永久保存到表中......提前谢谢

public class CustomerWorkOrder extends Activity implements OnClickListener {
EditText  etname ,etphone,etvname,etvno,etsdate,etldate,etremarks,etamount;
Button save,Load;
SharedPreferences SomeData;
TextView tv;
public static String filename="MySharedString";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_customer_work_order);
    save=(Button) findViewById(R.id.button1);
    Load=(Button) findViewById(R.id.button2);
    etname=(EditText) findViewById(R.id.editText1name);
    etphone=(EditText) findViewById(R.id.editText2pnum);
    etvno=(EditText) findViewById(R.id.editText3vvno);
etvname=(EditText) findViewById(R.id.editText4vvname);
etsdate=(EditText) findViewById(R.id.editText6sdate);
etldate=(EditText) findViewById(R.id.editText5ldts);
etamount=(EditText) findViewById(R.id.editText7amnt);
etremarks=(EditText) findViewById(R.id.editText8remk);

    save.setOnClickListener(this);
    Load.setOnClickListener(this);
    SomeData=getSharedPreferences(filename, 0);

}



@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    switch(arg0.getId()){
    case R.id.button1:
        String stringData=etname.getText().toString();
        String stringData1=etphone.getText().toString();
        String stringData2=etvno.getText().toString();
        String stringData3=etvname.getText().toString();
        String stringData4=etsdate.getText().toString();
        String stringData5=etldate.getText().toString();
        String stringData6=etamount.getText().toString();
        String stringData7=etremarks.getText().toString();
        SharedPreferences.Editor editor=SomeData.edit();
        editor.putString("SharedString", stringData);
        editor.putString("SharedString1", stringData1);
        editor.putString("SharedString2", stringData2);
        editor.putString("SharedString3", stringData3);
        editor.putString("SharedString4", stringData4);
        editor.putString("SharedString5", stringData5);
        editor.putString("SharedString6", stringData6);
        editor.putString("SharedString7", stringData7);
        editor.commit();
        etname.setText("");

        etphone.setText("");
        etvno.setText("");
        etvname.setText("");
        etsdate.setText("");
        etldate.setText("");
        etamount.setText("");
        etremarks.setText("");

    break;

    case R.id.button2:
        SomeData=getSharedPreferences(filename, 0);
        String dataReturned=SomeData.getString("SharedString", "could not load the data");
        String dataReturned1=SomeData.getString("SharedString1", "could not load the data");
        String dataReturned2=SomeData.getString("SharedString2", "could not load the data");
        String dataReturned3=SomeData.getString("SharedString3", "could not load the data");
        String dataReturned4=SomeData.getString("SharedString4", "could not load the data");
        String dataReturned5=SomeData.getString("SharedString5", "could not load the data");
        String dataReturned6=SomeData.getString("SharedString6", "could not load the data");
        String dataReturned7=SomeData.getString("SharedString7", "could not load the data");
        etname.setText(dataReturned);
        etphone.setText(dataReturned1);
        etvno.setText(dataReturned2);
        etvname.setText(dataReturned3);
        etsdate.setText(dataReturned4);
        etldate.setText(dataReturned5);
        etamount.setText(dataReturned6);
        etremarks.setText(dataReturned7);
        break;


}

}}

4

1 回答 1

0

也许这个优秀的教程会让你快速开始使用 SQLite。

于 2013-05-17T15:19:37.240 回答