Get editText value and use to Button

From: kartheeswaran
Sent on: Saturday, September 21, 2013 8:00 PM
Hi,
 I have four editText. I used sharedPreference for saving editText and get it later. I passed this editText value to another Activity button. I need to set first editText value to button. I used  

demomap.put(et.getText().toString(), et1.getText().toString());  demomap.put(et2.getText().toString(), et3.getText().toString());

But 2 buttons creating with et editText value and et2 editText value.

Code:


Activity:

et=(EditText)findViewById(R.id.meal);
et1=(EditText)findViewById(R.id.pieces);
et2=(EditText)findViewById(R.id.portions);
et3=(EditText)findViewById(R.id.ml);
save=(Button)findViewById(R.id.submit_data);


save.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {

 final Map<String, String> demomap = new HashMap<String, String>();
               demomap.put(et.getText().toString(), et1.getText().toString());
               demomap.put(et2.getText().toString(), et3.getText().toString());
               SharedPreferences preferences = getSharedPreferences("CREATE_MEAL",
                       0);
               SharedPreferences.Editor editor = preferences.edit();
               for (Entry<String, String> entry : demomap.entrySet()) {
                   editor.putString(entry.getKey(), entry.getValue());
               }
               editor.commit();

               Intent intent=new Intent(Activity.this,Activity1t.class);
               startActivity(intent);
}
});



Activity 1:

Here i set Button text from Activity SharedPrefereence.


demomap = new HashMap<String, String>();
        SharedPreferences preferences = getSharedPreferences("CREATE_MEAL", 0);
        for (Entry<String, ?> entry : preferences.getAll().entrySet()) {
            demomap.put(entry.getKey(), entry.getValue().toString());
        }
        LinearLayout layout = (LinearLayout) findViewById(R.id.linear);
        
     
        Iterator myVeryOwnIterator = demomap.keySet().iterator();
        while (myVeryOwnIterator.hasNext()) {
            String key = (String) myVeryOwnIterator.next();
            String value = (String) demomap.get(key);
            button = new Button(this);
            button.setText(value);
            layout.addView(button);




Regards,
karthees

Our Sponsors

  • Though Works

    Location Sponsor

  • GTUG

    Sponsor

  • Yourstory.in

    Media Partner

  • Startup Weekend

    Community Partner

  • Yahoo

    Location Sponsor

  • Intel

    Location Sponsor

  • Apigee

    Location Sponsor

  • Intuit

    Location Sponsor

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy