Search when pressing "Enter" button

This commit is contained in:
PhilippC 2013-03-21 01:22:27 +01:00
parent f5f6eb055b
commit 1106f618eb
2 changed files with 32 additions and 22 deletions

View File

@ -17,10 +17,12 @@
<EditText <EditText
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="text"
android:hint="@string/search_hint" android:hint="@string/search_hint"
android:layout_toLeftOf="@id/search_button" android:layout_toLeftOf="@id/search_button"
android:singleLine="true" android:singleLine="true"
android:layout_below="@id/search_label" android:layout_below="@id/search_label"
android:imeOptions="actionSearch"
android:id="@+id/searchEditText" /> android:id="@+id/searchEditText" />
<ScrollView <ScrollView
android:minWidth="25px" android:minWidth="25px"

View File

@ -66,13 +66,28 @@ namespace keepass2android
//TODO: "Enter"-Key should run the search //TODO: "Enter"-Key should run the search
btnSearch.Click += (object sender, EventArgs e) => btnSearch.Click += (object sender, EventArgs e) =>
{
PerformSearch();
};
FindViewById<EditText>(Resource.Id.searchEditText).EditorAction += (object sender, TextView.EditorActionEventArgs e) =>
{
if (e.ActionId == Android.Views.InputMethods.ImeAction.Search) {
PerformSearch();
}
};
}
void populateCheckBox(int resId, bool value)
{
((CheckBox) FindViewById(resId)).Checked = value;
}
void PerformSearch()
{ {
String searchString = ((EditText)FindViewById(Resource.Id.searchEditText)).Text; String searchString = ((EditText)FindViewById(Resource.Id.searchEditText)).Text;
if (String.IsNullOrWhiteSpace(searchString)) if (String.IsNullOrWhiteSpace(searchString))
return; return;
SearchParameters spNew = new SearchParameters(); SearchParameters spNew = new SearchParameters();
Intent searchIntent = new Intent(this, typeof(SearchResults)); Intent searchIntent = new Intent(this, typeof(SearchResults));
searchIntent.PutExtra("SearchInTitles", GetCheckBoxValue(Resource.Id.cbSearchInTitle)); searchIntent.PutExtra("SearchInTitles", GetCheckBoxValue(Resource.Id.cbSearchInTitle));
searchIntent.PutExtra("SearchInUrls", GetCheckBoxValue(Resource.Id.cbSearchInUrl)); searchIntent.PutExtra("SearchInUrls", GetCheckBoxValue(Resource.Id.cbSearchInUrl));
@ -86,15 +101,8 @@ namespace keepass2android
searchIntent.PutExtra("CaseSensitive", GetCheckBoxValue(Resource.Id.cbCaseSensitive)); searchIntent.PutExtra("CaseSensitive", GetCheckBoxValue(Resource.Id.cbCaseSensitive));
searchIntent.PutExtra("ExcludeExpired", GetCheckBoxValue(Resource.Id.cbExcludeExpiredEntries)); searchIntent.PutExtra("ExcludeExpired", GetCheckBoxValue(Resource.Id.cbExcludeExpiredEntries));
searchIntent.PutExtra(SearchManager.Query, searchString); searchIntent.PutExtra(SearchManager.Query, searchString);
StartActivityForResult(searchIntent, 0);
StartActivityForResult(searchIntent,0);
Finish(); Finish();
};
}
void populateCheckBox(int resId, bool value)
{
((CheckBox) FindViewById(resId)).Checked = value;
} }
} }
} }