开发者

Android: Use edittext input to set text of a button?

开发者 https://www.devze.com 2023-03-11 02:53 出处:网络
I save my edditext text: final EditText Zipcodeinput 开发者_高级运维= (EditText) findViewById(R.id.Zipcode);

I save my edditext text:

final EditText Zipcodeinput 开发者_高级运维= (EditText) findViewById(R.id.Zipcode);


SharedPreferences settings = getSharedPreferences("cars4sale",0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("zip", Zipcodeinput.getText().toString());
editor.commit();

I want to use the string "zip" to set the android:text=" " for one of my Buttons. I'm don't know how to go about this I've read about layoutinflator but it seems overly complex for what I'm trying to do.

Thanks for the help in advance, -Nick


First you would find the Button in question

Button button1 = (Button)findViewById(R.id.button1);

and then use the setText method to change its text

SharedPreferences settings = getSharedPreferences("cars4sale",0);
String zipStr = settings.getString("zip", "");    
button1.setText(zipStr);
0

精彩评论

暂无评论...
验证码 换一张
取 消