I have a Fragment. This fragment on his onCreateView method the view loaded has a ListView(A) (which is filled in the Adapter(A)). However, this ListView(A) has another ListView(B) inside of it. So now, I have to call an adapter(B) to fill this listview(B). if I call it from the fragment i get a null pointer, if i call it from the Adapter(A) it doesn't crash but it doesn't work.
How do you call an adapter inside another one.
This is the Fragment's code:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mContentView = inflater.inflate(R.layout.fragment_kidscontacts, container, false);
mAdapter = new KidsContactsAdapter(getActivity());
final ListView list = (ListView) mContentView.findViewById(R.id.listViewKidsContacts);
list.setAdapter(mAdapter);
return mContentView;
}
where the mAdapter is a call for the Adapter(A) I made. And the mContentView is a simple View. Now, the code of the Adapter(A), I have a Holder object created named holder (which holds the elements in the xml).
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder; //this is the holder object I created
if (convertView == null) { //View received from parameter.
convertView = LayoutInflater.from(mContext).inflate(R.layout.kids_contacts_list_item, parent, false);
holder = new ViewHolder();
holder.listViewKidsContacts = (ListView) convertView.findViewById(R.id.insidelistViewKidsContacts); //ListView(B)
holder.kidImage = (ImageView) convertView.findViewById(R.id.kid_image);
holder.statusImageView = (ImageView) convertView.findViewById(R.id.status_image_view);
holder.nameTxtView = (TextView) convertView.findViewById(R.id.kid_friend_txtview);
holder.statusTextView = (TextView) convertView.findViewById(R.id.kid_status_txtview);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//Some work I do with the holder items assigning them
//Trying to fill the ListView(B)
KidsInsideContactsAdapter mAdapter = new KidsInsideContactsAdapter(((Activity)mContext)); //This is the adapter(B)
holder.listViewKidsContacts.setAdapter(mAdapter); //Assign the adapter(B) to the ListView(B)
return convertView;
}
I have some logs inside the adapter(B), but they are not shown in LogCat. And neither is the listview filled. It shows like if there was no listview. However in the xml there it is.