0

how to save the text given to edit text, after clicking the save action button in action bar that should save to another activity. my first activity Add.java

public class Add extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        getActionBar().setDisplayShowHomeEnabled(false);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflate=getMenuInflater();
        getMenuInflater().inflate(R.menu.activity_add_action, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.save:save();
                return true;
            case R.id.cancel:cancelnavi();
                return true;    
        }
        return super.onOptionsItemSelected(item);
    }

    private void save() {
        EditText titlename;
        titlename=(EditText)findViewById(R.id.edittitle);
        String title=titlename.getText().toString();
        if (title.equalsIgnoreCase("")){
            Toast.makeText(Add.this, "Script title should not be empty", Toast.LENGTH_LONG).show();
        } else {
            Intent i;
            i=new Intent(getApplicationContext(), Scripts.class);
            i.putExtra("n", titlename.getText().toString());
            startActivityForResult(i, 0);
            titlename.setText("");
        }
    }
}

It should be saved to scripts.java

public class Scripts extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scripts); 
        getActionBar().setDisplayShowHomeEnabled(false);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflate=getMenuInflater();
        getMenuInflater().inflate(R.menu.activity_main_actions, menu);

        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_edit:editscript();
            break;  
        }
        return true;
    }

    private void editscript() {
        Intent editinIntent;
        editinIntent=new Intent(Scripts.this, Edit.class);
        startActivity(editinIntent);
    }
}
simo.3792
  • 2,102
  • 1
  • 17
  • 29
  • I believe , that you can find answer here: http://stackoverflow.com/questions/3510649/how-to-pass-a-value-from-one-activity-to-another-in-android – Sparrow_ua Sep 09 '14 at 02:37

1 Answers1

0

Maybe this can help you.

public class Scripts extends Activity {

     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_scripts); 
         getActionBar().setDisplayShowHomeEnabled(false);



        //Extract the data

         String yourTitle = getIntent().getStringExtra("n");
     }
}
kelvincer
  • 5,929
  • 6
  • 27
  • 32