我一直遇到从EditText到TextView的文本出现问题,EditText正在自定义操作栏中膨胀,我知道解决方案非常简单,但我无法找到解决方法,我能够在其他活动但未能在此活动中执行此操作,下面是我的代码:
ActionBar mActionBar = getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.search_customactionbar, null);
ImageButton mstartsearch = (ImageButton) mCustomView.findViewById(R.id.msearch1);
mActionBar.setCustomView(mCustomView);
searchbox = (EditText)findViewById(R.id.searchbox1);
mActionBar.setDisplayShowCustomEnabled(true);
searchQuery = (TextView)findViewById(R.id.itemName);
searchQuery.setVisibility(View.INVISIBLE);
mstartsearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchQuery.setText(searchbox.getText().toString());
searchQuery.setVisibility(View.VISIBLE);
}
});
当我运行此代码时,我收到以下错误:
at aubry.chromio.com.letstalksampo.SearchPost$1.onClick(SearchPost.java:154)
at android.view.View.performClick(View.java:4472)
at android.view.View$PerformClick.run(View.java:18599)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5883)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:688)
at dalvik.system.NativeStart.main(Native Method)
问题出在哪里?