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
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="@string/search_hint"
android:layout_toLeftOf="@id/search_button"
android:singleLine="true"
android:layout_below="@id/search_label"
android:imeOptions="actionSearch"
android:id="@+id/searchEditText" />
<ScrollView
android:minWidth="25px"

View File

@ -67,35 +67,43 @@ namespace keepass2android
btnSearch.Click += (object sender, EventArgs e) =>
{
String searchString = ((EditText)FindViewById(Resource.Id.searchEditText)).Text;
if (String.IsNullOrWhiteSpace(searchString))
return;
SearchParameters spNew = new SearchParameters();
Intent searchIntent = new Intent(this, typeof(SearchResults));
searchIntent.PutExtra("SearchInTitles", GetCheckBoxValue(Resource.Id.cbSearchInTitle));
searchIntent.PutExtra("SearchInUrls", GetCheckBoxValue(Resource.Id.cbSearchInUrl));
searchIntent.PutExtra("SearchInPasswords", GetCheckBoxValue(Resource.Id.cbSearchInPassword));
searchIntent.PutExtra("SearchInUserNames", GetCheckBoxValue(Resource.Id.cbSearchInUsername));
searchIntent.PutExtra("SearchInNotes", GetCheckBoxValue(Resource.Id.cbSearchInNotes));
searchIntent.PutExtra("SearchInGroupNames", GetCheckBoxValue(Resource.Id.cbSearchInGroupName));
searchIntent.PutExtra("SearchInOther", GetCheckBoxValue(Resource.Id.cbSearchInOtherStrings));
searchIntent.PutExtra("SearchInTags", GetCheckBoxValue(Resource.Id.cbSearchInTags));
searchIntent.PutExtra("RegularExpression", GetCheckBoxValue(Resource.Id.cbRegEx));
searchIntent.PutExtra("CaseSensitive", GetCheckBoxValue(Resource.Id.cbCaseSensitive));
searchIntent.PutExtra("ExcludeExpired", GetCheckBoxValue(Resource.Id.cbExcludeExpiredEntries));
searchIntent.PutExtra(SearchManager.Query, searchString);
StartActivityForResult(searchIntent,0);
Finish();
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;
if (String.IsNullOrWhiteSpace(searchString))
return;
SearchParameters spNew = new SearchParameters();
Intent searchIntent = new Intent(this, typeof(SearchResults));
searchIntent.PutExtra("SearchInTitles", GetCheckBoxValue(Resource.Id.cbSearchInTitle));
searchIntent.PutExtra("SearchInUrls", GetCheckBoxValue(Resource.Id.cbSearchInUrl));
searchIntent.PutExtra("SearchInPasswords", GetCheckBoxValue(Resource.Id.cbSearchInPassword));
searchIntent.PutExtra("SearchInUserNames", GetCheckBoxValue(Resource.Id.cbSearchInUsername));
searchIntent.PutExtra("SearchInNotes", GetCheckBoxValue(Resource.Id.cbSearchInNotes));
searchIntent.PutExtra("SearchInGroupNames", GetCheckBoxValue(Resource.Id.cbSearchInGroupName));
searchIntent.PutExtra("SearchInOther", GetCheckBoxValue(Resource.Id.cbSearchInOtherStrings));
searchIntent.PutExtra("SearchInTags", GetCheckBoxValue(Resource.Id.cbSearchInTags));
searchIntent.PutExtra("RegularExpression", GetCheckBoxValue(Resource.Id.cbRegEx));
searchIntent.PutExtra("CaseSensitive", GetCheckBoxValue(Resource.Id.cbCaseSensitive));
searchIntent.PutExtra("ExcludeExpired", GetCheckBoxValue(Resource.Id.cbExcludeExpiredEntries));
searchIntent.PutExtra(SearchManager.Query, searchString);
StartActivityForResult(searchIntent, 0);
Finish();
}
}
}