-3
這是我的java文件..我想通過點擊「提交」按鈕保存我輸入的號碼......任何人都可以幫助我完成我的編碼?保存在Button上的號碼點擊
public void onCreate(Bundle savedInstanceState)
{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1=(EditText)findViewById(R.id.no);
b1=(Button)findViewById(R.id.button);
sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String ph = ed1.getText().toString();
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Phone, ph);
editor.commit();
Toast.makeText(MainActivity.this,"Thanks",Toast.LENGTH_LONG).show();
Toast msg = Toast.makeText(getBaseContext(),
"Succeed", Toast.LENGTH_LONG);
msg.show();
}
});
}}}
請看這裏http://stackoverflow.com/help/mcve如何正確提問 – Guenther