i am trying to send one string from one activity to another and posting it on a edittext field I have googled a lot but i couldn't find anything (maybe its my fault)
Here is the code MainActivity (with the string)
public class MainActivity extends ActionBarActivity {
private Button mbutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String go="send?";
final Context context=this;
mbutton = (Button)findViewById(R.id.hello);
mbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(context, work.class);
intent.putExtra("contents", go);
startActivity(intent);
}
});
}
}
My second activity
public class work extends Activity {
EditText codeTxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
codeTxt = (EditText) findViewById(R.id.txtCode);
Bundle extras = getIntent().getExtras();
final String dam= extras.getString("contents");
codeTxt.setText(dam);
}
}
I get this app as stope working after pressing the button Keep in mind that this is just a draft to learn who to do this to use in other app.
Aucun commentaire:
Enregistrer un commentaire