gpt4 book ai didi

java - getView() 方法在带有 gridview 的自定义适配器中未调用

转载 作者:行者123 更新时间:2023-12-02 04:29:21 28 4
gpt4 key购买 nike

当我调试代码时,它正在调用 InviteListAdapter 中的构造函数,但没有调用 getView() 方法。我已经尝试了 stackoverflow 上提供的多种解决方案,但没有一个有效。希望任何人都能找到错误或解决方案。

invitableFriends.size()    

返回大于 0 的值。

InviteListAdapter

public class inviteListAdapter extends ArrayAdapter<JSONObject> {

private final Context context;
private final List<JSONObject> invitableFriends;
private ImageView profilePicView;

public inviteListAdapter(Context context, List<JSONObject> invitableFriends) {
super(context, R.layout.invite_adapter, invitableFriends);
this.context = context;
this.invitableFriends = invitableFriends;
}


@Override
public View getView(int position, View convertView, ViewGroup parent){


LayoutInflater inflater = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);

View listItemView = inflater.inflate(R.layout.invite_adapter, parent, false);

profilePicView = (ImageView) listItemView.findViewById(R.id.inviteListItemProfilePic);
TextView nameView = (TextView) listItemView.findViewById(R.id.inviteListItemName);

JSONObject currentUser = invitableFriends.get(position);

nameView.setText(currentUser.optString("first_name"));


return listItemView;
}

}

first.java

public View onCreateView (
LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_first,container, false);

invitesGridView = (GridView)view.findViewById(R.id.invitesGridView);

return view;
}


final inviteListAdapter adapter = new inviteListAdapter(this,inviteFriendList);
invitesGridView.setAdapter(adapter);
adapter.notifyDataSetChanged();

最佳答案

public View onCreateView (
LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_first,container, false);

invitesGridView = (GridView)view.findViewById(R.id.invitesGridView);
final inviteListAdapter adapter = new inviteListAdapter(this,inviteFriendList);
invitesGridView.setAdapter(adapter);
adapter.notifyDataSetChanged();

return view;
}

在onCreateView中调用setAdapter

关于java - getView() 方法在带有 gridview 的自定义适配器中未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31690477/

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