简体   繁体   中英

how to pass edittext value in actionbar from one activity to another?

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
         MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.main_activity_bar, menu);
            View v = (View) menu.findItem(R.id.my_action).getActionView();

            /** Get the edit text from the action view */
            txtSearch = ( EditText ) v.findViewById(R.id.myActionEditText);

            edit_searchtext=txtSearch.getText().toString();
            /** Setting an action listener */


            ImageView Search = ( ImageView ) v.findViewById(R.id.search);
            Search.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    search_value = txtSearch.getText().toString();
                    Toast.makeText(getBaseContext(), txtSearch.getText().toString() , Toast.LENGTH_SHORT).show();
//                   Intent intent  = new Intent(MainActivity.this,Display.class);
//                      intent.putExtra("search_value", txtSearch.getText().toString());
//                      startActivity(intent);

                }


            });

            return super.onCreateOptionsMenu(menu);
    }

I want to store edittext value in a string and pass it to another activity... i have a string edit_searchtext and i am storing edit text value into the string...but the value is not stored in the variable and i am able to pass the variable edit_searchtext to another activity

Hmm, what is this line doing?

edit_searchtext=txtSearch.getText().toString();

And you are calling that line from OnCreate methods, which will probably return null from EditText since it's just created/being created.

The other things look OK.

EDIT: Did you set Search (ImageView) clickable in XML, by default it is false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM