gpt4 book ai didi

java - 如果我没有在该特定类中声明它,如何在该类上调用 getItem 方法

转载 作者:太空宇宙 更新时间:2023-11-04 10:47:14 24 4
gpt4 key购买 nike

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;
if(listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
Word currentWord = getItem(position);
TextView miwokTextView = (TextView) listItemView.findViewById(R.id.miwok_text_view);

miwokTextView.setText(currentWord.getmMiwokTranslation());

TextView defaultTextView = (TextView) listItemView.findViewById(R.id.Default_text_view);

defaultTextView.setText(currentWord.getmDefaultTranslation());

ImageView iconView = (ImageView) listItemView.findViewById(R.id.image);
// Get the image resource ID from the current AndroidFlavor object and
// set the image to iconView
iconView.setImageResource(currentWord.getmImageResourceId());

return listItemView;
}
}

如果我没有在特定的类中声明它,我如何在该类上调用 getItem 方法。还请告诉我它是如何工作的以及它的用途。

上面给出的代码是一个基本的适配器类,它允许一个 Word 类包含两个字符串和一个图像资源整型变量及其 getter 方法。我的目的是在单个列表项中显示两个 TextView 和一个 ImageView 。代码很好,应用程序也运行良好。

最佳答案

getItem 定义在父类 ArrayAdapter. 中如果需要,您可以覆盖它。

关于java - 如果我没有在该特定类中声明它,如何在该类上调用 getItem 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48263692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com