Android-dev.it Community

 
Annunci

:arrow: Benvenuto!, se non sei ancora un utente registrato: puoi registrati qui, oppure effettua il login
:arrow: Apri un forum sul tuo nuovo smartphone Android e collabora con noi! (dettagli)

www.agendadigitale.org
Image


Sponsor
It is currently Fri May 18, 2012 5:51 pm

All times are UTC + 1 hour


 Topics   Replies   Views   Last post 
No new posts Apri un forum sul tuo nuovo smartphone Android!

[ Go to page: 1, 2, 3 ]

by ReattileGar on Fri May 18, 2012 5:27 pm in Amministrazione

27

12412

Fri May 18, 2012 5:27 pm

ReattileGar

No new posts Новый: базы для хрумера - профессиональный софт для СЕО.

by Renatafe on Fri May 18, 2012 3:14 pm in Amministrazione

0

4

Fri May 18, 2012 3:14 pm

Renatafe

No new posts Pace is undoubtedly the vital affordable Jerseys Wholesale d

by barnettmmolive2012 on Wed May 16, 2012 7:36 am in Amministrazione

1

44

Wed May 16, 2012 7:36 am

barnettmmolive2012

No new posts Problema di compatibilità app

by deran on Tue May 15, 2012 10:44 am in Sviluppo e programmazione in Android

4

187

Tue May 15, 2012 10:44 am

deran

No new posts Applicazione inserimento eventi

by mauro21 on Mon May 14, 2012 9:20 pm in Sviluppo e programmazione in Android

0

23

Mon May 14, 2012 9:20 pm

mauro21




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Caricamento variabile da EditText mediante Button
PostPosted: Sun May 29, 2011 7:44 am 
Offline
User avatar

Joined: Sat May 21, 2011 9:53 am
Posts: 3
Cellulare Android: Samsung i5800 Galaxy mini
Operatore: Wind
Punti Android: ?
Ciao Ragazzi ho il seguente problema che non riesco a risolvere:
in pratica ho creato una funzione che prende il valore inserito dall'utente in una EditText e lo invia tramite SMS premendo un Bottone. La funzione ha il difetto di inviare il msg e solo successivamente caricare il valore. Quindi in pratica manderà sempre il valore di default, non quello che l'utente scrive.
Questa è la mia funzione:

Code:
public class Main extends Activity {
      
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Main);

// Carico il mio valore di default (0) o quello presente nelle preferences (sotto il nome Value)
final SharedPreferences settings = getPreferences(0);
final String MyValue = settings.getString("Value", "0");

//Scrivo il valore di default o quello presente nelle preferences nella EditText
final EditText et = (EditText) findViewById(R.id.EditText1);
      et.setText(MyValue);

// Il Tasto GO!
      Button btnConfig2 = (Button) this.findViewById(R.id.btnConfig2);
      btnConfig2.setOnClickListener(new OnClickListener() {
         public void onClick(View v) {
            // do something on click:

// Prima di tutto salvo il valore scritto nelle preferenze...
SharedPreferences.Editor editor = settings.edit();
editor.putString("Value", MyValue.getText().toString());
editor.commit();

// ...poi mando un SMS
SmsManager sms = SmsManager.getDefault();
// il numero di telefono è quello dell'emulatore...
String destination = "5556";
String message = "Hai scritto: " + MyValue;
sms.sendTextMessage(destination, null, message, null, null);
}
});
}
}



La stessa cosa mi succede quando provo a passare con un tasto dall'Activity "Main" all'activity "SecondaPagina" trasportando dei valori (variabili) mediante l'intent. :help:

Visto che ci sono ne approfitto: secondo voi il modo che ho usato per salvare il valore di default è appropriato (a me basta che funzioni)?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
phpBB SEO

All trademarks and logos used in this site are of properties of their respective owners.