Пользовательский SearchView TextChange - PullRequest
1 голос
/ 20 февраля 2020

Привет! Я создал пользовательский SearchView, но я не могу получить введенный текст пользователем

, это мой view_search. xml

        <EditText
            android:id="@+id/search_input_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            android:layout_toEndOf="@id/close_search_button"
            android:hint="جستجو..."
            android:layout_toRightOf="@+id/close_search_button"/>

и я положил его на панель инструментов

            <ir.mahdi.circulars.CustomView.SearchView
                android:id="@+id/searchView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:theme="@style/SearchView"
                app:showDividers="none" />

и это мой класс searchview

class SearchView(
    context: Context,
    attrs: AttributeSet
) : FrameLayout(context, attrs) {

    init {
        LayoutInflater.from(context)
            .inflate(R.layout.view_search, this, true)

    }

Я не знаю, как обращаться с обменом текстами searchview

1 Ответ

0 голосов
/ 20 февраля 2020

Вы пробовали это в Kotlin?

var searchView = findViewById<EditText>(R.id.search_input_text)

var searchValue = searchView?.editableText.toString()

Если вы хотите использовать слушатель в Java;

 searchView.addTextChangedListener(new TextWatcher() {

   @Override
   public void afterTextChanged(Editable s) {}

   @Override    
   public void beforeTextChanged(CharSequence s, int start,
     int count, int after) {
   }

   @Override    
   public void onTextChanged(CharSequence s, int start,
     int before, int count) {

   }
  });
...