Ich habe einen EditText in der Symbolleiste meines Layouts hinzugefügt. Ich möchte auf den Wert von EditText zugreifen, wenn Fertig von der Soft-Tastatur gedrückt wird. Ich habe den EditText in der onCreate() meiner Aktivität initialisiert. Ich möchte auf diesen EditText-Wert zugreifen und meinen API-Anruf füttern.Zugriff auf den Wert von EditText in ToolBar hinzugefügt
hier ismy xml Layout
<FrameLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/Toolbar" >
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/search_edit_text"
android:singleLine="true"
android:textCursorDrawable="@drawable/edit_text_cursor"
android:backgroundTint="@android:color/white"
android:imeOptions="actionSearch"
/>
</android.support.v7.widget.Toolbar>
</FrameLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_ff"
android:layout_below="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/iv_ff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/stat_no_connection"
android:visibility="invisible" />
<ProgressBar
android:id="@+id/prog_bar_ff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
/>
<ImageView
android:id="@+id/nothing_to_show_here"
android:layout_width="match_parent"
android:layout_below="@+id/toolbar_container"
android:layout_height="match_parent"
android:src="@drawable/stat_nothing_gray"
android:scaleType="fitCenter"
android:layout_centerInParent="true"
android:visibility="invisible"/>
und das ist mein onCreate()
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = this.getIntent()
mUserEmail = intent.getStringExtra(Constants.USER_EMAIL);
setContentView(R.layout.search_list_activity);
RecyclerView mRecy = (RecyclerView) findViewById(R.id.rv_ff);
mProgBar = (ProgressBar) findViewById(R.id.prog_bar_ff);
mRecy.setLayoutManager(new LinearLayoutManager(this));
mImageView = (ImageView) findViewById(R.id.iv_ff);
nothingToShow = (ImageView) findViewById(R.id.nothing_to_show_here);
Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
/* Common toolbar setup */
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
searchEditText = (EditText) findViewById(R.id.search_edit_text);
Log.d(TAG+"init","search");
mQueryString = searchEditText.getText().toString();
Log.d(TAG+"mQuery",mQueryString);
searchEditText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
Log.d(TAG+"mQuery",mQueryString);
return true;
}
return false;
}
});
mAdapter = new OfferAdapter(this);
mRecy.setAdapter(mAdapter);
}
`
searchEditText.getText() –