прошу прощения за мой плохой английский, мой вопрос может показаться глупым, но мне интересно, как работает пользовательский адаптер массива в Android Studio 3.1
Сначала я создаю собственный адаптер для обработки своего массива объектов, которые он выглядиткак это:
package com.example.android.miwok;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.app.Activity;
import java.util.ArrayList;
public class WordAdapter extends ArrayAdapter<Word> {
public WordAdapter(Activity context, ArrayList<Word> words){
// Here, we initialize the ArrayAdapter's internal storage for the context and the list.
// the second argument is used when the ArrayAdapter is populating a single TextView.
// Because this is a custom adapter for two TextViews and an ImageView, the adapter is not
// going to use this second argument, so it can be any value. Here, we used 0.
super(context,0,words);
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View listItemView = convertView;
// Check if the existing view is being reused, otherwise inflate the view
if(listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
Word currentWord = getItem(position);
TextView defaultWord = (TextView) listItemView.findViewById(R.id.default_text_view);
defaultWord.setText(currentWord.getDefaultTranslation());
TextView miwokWord = (TextView) listItemView.findViewById(R.id.miwok_text_view);
miwokWord.setText(currentWord.getMiwokTranslation());
ImageView img = (ImageView) listItemView.findViewById(R.id.img);
img.setImageResource(currentWord.getImageResourceId());
return listItemView;
}
}
моя структура объекта выглядит следующим образом:
package com.example.android.miwok;
public class Word {
private String mDefaultTranslation;
private String mMiwokTranslation;
private int mImageResourceId;
public Word(String DefaultTranslation, String MiwokTranslation){
mDefaultTranslation = DefaultTranslation;
mMiwokTranslation = MiwokTranslation;
}
public Word(String DefaultTranslation, String MiwokTranslation, int imageResourceId){
mDefaultTranslation = DefaultTranslation;
mMiwokTranslation = MiwokTranslation;
mImageResourceId = imageResourceId;
}
public String getDefaultTranslation() {
return mDefaultTranslation;
}
public String getMiwokTranslation() {
return mMiwokTranslation;
}
public int getImageResourceId() {
return mImageResourceId;
}
}
, поскольку вы можете видеть, что слово object имеет 2 конструктора, первый принимает 2 строковых значения и одно значение int, котороеэто идентификатор ресурса изображения, второй принимает только 2 строковых значения.
код выполняется без ошибок, что меня запутывает, потому что когда я использую второй конструктор объекта, я ожидал получить пустой список в действиипотому что wordAdapter нужен идентификатор изображения для работы, но он работает отлично, любые подсказки, ребята;