Окно поиска Android в панели действий для объектов в адаптере массива listView - PullRequest
0 голосов
/ 12 сентября 2018

Я хочу вставить в панель действий поле автозаполнения, наподобие того, которое есть в WhatsApp, которое ищет объекты в списках просмотра из разных действий. Внутри некоторых из этих действий есть фрагменты, но все они содержат представления списка с объектами, содержащими слова, изображения и аудио. Я пытался найти решение, но все, что я получил, это поиск простых списков, и я не смог понять. все еще новое в Android. Вот один из фрагментов кода моей активности listItems

final ArrayList<Word> word = new ArrayList<Word>();

    word.add(new Word("beat","rova",R.raw.rova));
    word.add(new Word("buy","tenga",R.raw.tenga));
    word.add(new Word("come","huya",R.raw.huya));
    word.add(new Word("begin","taga",R.raw.tanga));
    word.add(new Word("bite","ruma",R.raw.ruma));
    word.add(new Word("break","gura",R.raw.gura));
    word.add(new Word("burn","pisa",R.raw.pisa));
    word.add(new Word("catch","bata",R.raw.bata));

Вот мой класс адаптера

public class WordAdapter extends ArrayAdapter<Word> {

private int mColorResourseId;

private static final String LOG_TAG = WordAdapter.class.getSimpleName();

public WordAdapter(Activity context, ArrayList<Word> word,int colorResourseId){
    super(context,0,word);
    mColorResourseId =  colorResourseId;
}



@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View listItemView = convertView;
    if(listItemView == null){
        listItemView = LayoutInflater.from(getContext()).inflate(R.layout.custom_list_view,parent,false);
    }
    Word currentWord = getItem(position);

    // Find the TextView in the list_item.xml layout with the ID version_name
    TextView shona = (TextView) listItemView.findViewById(R.id.shona);
    // Get the version name from the current Word object and
    // set this text on the name TextView
    shona.setText(currentWord.getShonaTranslation());

    // Find the TextView in the list_item.xml layout with the ID version_number
    TextView english = (TextView) listItemView.findViewById(R.id.english);
    // Get the version number from the current word object and
    // set this text on the number TextView
    english.setText(currentWord.getDefaultTranslation());

    // Find the ImageView in the list_item.xml layout with the ID list_item_icon
    ImageView image = (ImageView) listItemView.findViewById(R.id.image);
    if(currentWord.hasImage()){
        image.setImageResource(currentWord.getImageResourceId());
        image.setVisibility(View.VISIBLE);
    }else{
        image.setVisibility(View.GONE);
    }

    View linear = listItemView.findViewById(R.id.linear);
    int color = ContextCompat.getColor(getContext(), mColorResourseId);
    linear.setBackgroundColor(color);



    return listItemView;
}

Как вы можете видеть, в каждом объекте есть два слова, я хочу, чтобы пользователь искал по первому слову, но получил весь объект

...