如何设置Adapter
以显示ListFragment
,并尝试将代码设置为此底部
不起作用
ListFragment
只显示一个值(index = 0),其他索引不显示
ChatGroupMembersFragment.java
public class ChatGroupMembersFragment extends ListFragment {
ArrayList<ChatApiFriendListGroupModel> chatApiFriendListGroupModelArrayList = new ArrayList<>();
ArrayList<ChatApiFriendListGroupModel> chatApiFriendListGroupModels = new ArrayList<>();
private AdapChatGroupMembers adapChatGroupMembers;
public static ArrayList<ChatApiFriendListGroupModel> f =new ArrayList<>();
public static ChatGroupMembersFragment newInstance(ChatApiFriendListGroupModel member) {
f.add(member);
return new ChatGroupMembersFragment();
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Log.d("ChatGroupMembersFragmen","onViewCreated");
ShareData.tx_home_titlebar.setText(getActivity().getResources().getString(R.string.tx_group_member));
Member();
}
private void Member() {
for (ChatApiFriendListGroupModel chatApiFriend: f){
chatApiFriendListGroupModelArrayList.add(chatApiFriend);
}
adapChatGroupMembers = new AdapChatGroupMembers(getActivity(), chatApiFriendListGroupModelArrayList);
setListAdapter(adapChatGroupMembers);
adapChatGroupMembers.notifyDataSetChanged();
}
}
和myadapter
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHoder = new ViewHolder();
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView==null){
convertView = layoutInflater.inflate(R.layout.fragment_chat_group_members,parent ,false);
viewHoder.tx_name_member = (TextView) convertView.findViewById(R.id.tx_name_member);
viewHoder.img_profile_member =(ImageView) convertView.findViewById(R.id.img_profile_member);
viewHoder.tx_name_member.setTypeface(MainActivity.typeface_normal);
convertView.setTag(viewHoder);
}else {
viewHoder = (ViewHolder) convertView.getTag();
}
viewHoder.tx_name_member.setText(chatApiFriendListGroupModelArrayList.get(position).getMembers().get(position).getFirstname());
return convertView;
}
它只显示listview中的一个(get(0).getFirstName();
)
和我的数据在FirstName(get(0-6).getFirstName()
)
如何让所有价值显示ListFragment
?
答案 0 :(得分:2)
您的ArrayList
似乎只有一个元素,您可以在此处添加:
f.add(member);
因此,以下调用仅在位置为0
时返回一个元素:
chatApiFriendListGroupModelArrayList.get(position);
如果我理解正确且getMembers()
返回正确的数据集,您可能需要执行以下操作:
viewHoder.tx_name_member.setText(chatApiFriendListGroupModelArrayList.get(0)
.getMembers().get(position).getFirstname());
并相应地覆盖getCount()
:
@Override
public int getCount() {
return chatApiFriendListGroupModelArrayList.get(0)
.getMembers().size();
}