[英]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 我想将edittext值存储在字符串中并将其传递给另一个活动...我有一个字符串edit_searchtext,并且我将Edit text值存储到字符串中...但是该值未存储在变量中,并且我能够将变量edit_searchtext传递给另一个活动
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. 您正在从OnCreate方法中调用该行,由于刚刚创建/正在创建它,因此它可能会从EditText返回null。
The other things look OK. 其他事情看起来还可以。
EDIT: Did you set Search (ImageView) clickable in XML, by default it is false. 编辑:您是否在XML中将搜索(ImageView)设置为可点击,默认情况下为false。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.