我在使用CustomAdapter显示ListView时遇到问题。它总是空的,但与我使用GridView的方式相同,它可以工作。
部分代码 - gridview,这是有效的:
GridView gv;
View rootView = inflater.inflate(R.layout.mygridview, container, false);
gv = rootView.findViewById(R.id.gridview1);
gv.setAdapter(new CustomAdapter(getContext(), prgmNameListNew, prgmPopisNew, imgNameListNew, myDistNew));
在mygridview.xml中我只有一个 在我的CustomAdapter中:
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(con).inflate(R.layout.booklist_row2, parent, false);
holder = new ViewHolder();
holder.tv = convertView.findViewById(R.id.textView1);
...
所以在booklist_row2.xml中我有textView。这是有效的,但如果我想使用 ListView 而不是GridView,结果什么都不显示:
ListView gv;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.mylistview, container, false);
gv= rootView.findViewById(R.id.listview1);