Please tell me how to properly link ViewHolder with the GridView and its actions, say, a simple example, if possible, for understanding the structure.

Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants Vladyslav Matviienko , pavel , αλεχολυτ , cheops , Bald 26 Sep '16 at 5:39 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Did you use the search before asking a question? - Vladyslav Matviienko
  • @metalurgus yes, but there are not exactly those examples that I would like to see) - Inkognito
  • one
    That is, you are now offering us to guess, what kind of example do you want to see? And the prize will be the one who guesses? - Vladyslav Matviienko

2 answers 2

ViewHolder is an object that holds field references - because the findViewById() method is very resource-intensive. GridView is a layout layout.

All you need to know about linking these two things:

 mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); // Используйте этот метод, если уверены, что размер адаптера не будет меняться mRecyclerView.setHasFixedSize(true); // Первый входной параметр это контекст, второй количество колонок. GridLayoutManager glm=new GridLayoutManager(this,2); // Программно устанавливаете компоновщик (тут и происходит "связывание" в вашем понимании) mRecyclerView.setLayoutManager(glm); // Создаете инстанс ресайклера mAdapter = new CardViewDataAdapter(myDataset); // Устанавливаете адаптер к ресайклервью mRecyclerView.setAdapter(mAdapter); 

    Here is an example for ListView, I think for GridView it will also work!

     public class DataAdapter extends BaseAdapter { private Context mContext; private String[] mData; public DataAdapter(Context context, String[] objects) { mContext = context; mData = objects; } static class ViewHolder { TextView txtItem; } @Override public String getItem(int i) { return mData[i]; } @Override public View getView(int position, View convertView, ViewGroup viewGroup) { ViewHolder viewHolder; if (convertView == null){ LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.list_item, viewGroup, false); viewHolder = new ViewHolder(); viewHolder.txtItem = (TextView) convertView.findViewById(R.id.txtItem); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } viewHolder.txtItem.setText(getItem(position)); return convertView; } @Override public long getItemId(int i) { return i; } @Override public int getCount() { return mData.length; } }