【发布时间】:2016-09-11 16:20:45
【问题描述】:
这是我的 java 文件..我想通过单击“提交”按钮保存我输入的数字..谁能帮我完成我的编码?
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();
}
});
}}}
【问题讨论】:
-
查看这里stackoverflow.com/help/mcve了解如何正确提问