gpt4 book ai didi

Android 自定义 Listview 未显示

转载 作者:行者123 更新时间:2023-11-29 20:47:42 26 4
gpt4 key购买 nike

UserInfo 模型有三个字段名称、电子邮件、照片,但只想在 ListView 中显示名称。当用户点击 listview 然后获取所有字段,如姓名、照片电子邮件

还想在listview中设置过滤器

我的 ListView 适配器类

public class UsersAdapter extends  ArrayAdapter<UserInfo> {
ArrayList<UserInfo> users;
Context context;
LayoutInflater inflater;
public UsersAdapter(Context context, ArrayList<UserInfo> users) {
super(context,R.id.tvName, users);
this.users= users;
this.context= context;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder;
if(convertView == null) {
convertView = inflater.inflate(R.layout.items, null);
holder = new Holder();
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}

holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
holder.tvName.setText(users.get(position).getName());
return convertView;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}

@Override
public UserInfo getItem(int position) {
// TODO Auto-generated method stub
return users.get(position);
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
private class Holder {
TextView tvName;
}

最佳答案

问题是 getcount 方法,它应该如下所示。

@Override
public int getCount () {
return users.size();
}

关于Android 自定义 Listview 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30011870/

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