輸入框輸入內容 在鍵盤迴車改爲搜索

et_sns.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH){
                if (TextUtils.isEmpty(et_sns.getText().toString().trim())){
                    Toast.makeText(getActivity(), "請輸入內容", Toast.LENGTH_SHORT).show();
                    return true;
                }else {
                    list_books.clear();
                    getAllBookInfo(1, MAX_PAGE,0);
                    bookAdapter = new MoreBooksAdapter(getActivity(), list_books);
                    lv_sns.setAdapter(bookAdapter);
                }
                return true;
            }
            return false;
        }
    });
}
<EditText
    android:inputType="text"
    android:imeOptions="actionSearch"
    android:id="@+id/etSearch_answer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginRight="@dimen/space_normal"
    android:layout_marginTop="@dimen/space_narrower"
    android:layout_marginBottom="@dimen/space_narrower"
    android:background="@drawable/bg_radius_home"
    android:hint="@string/input_book_name"
    android:paddingLeft="32dp"
    android:singleLine="true" />
相關文章
相關標籤/搜索