I have a listfragment that I’m populating with a simplecursoradapter. However, only the first column is getting binded to the layout. Here is the code.
public class ContactList extends ListFragment
{
private ActivityDbAdapter mDbHelper;
private Long mRowId=Long.valueOf(1);
Activity mContext;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
mContext=getActivity();
mDbHelper=new ActivityDbAdapter(mContext);
mDbHelper.open();
Cursor activity = mDbHelper.fetchContacts(mRowId);
if (activity.moveToFirst())
{
String[] from = new String[]{ActivityDbAdapter.COLUMN_NAME_CONTACT1 ,
ActivityDbAdapter.COLUMN_NAME_CONTACT2,ActivityDbAdapter.COLUMN_NAME_CONTACT3,
ActivityDbAdapter.COLUMN_NAME_CONTACT4, ActivityDbAdapter.COLUMN_NAME_CONTACT5};
int[] to = new int[]{R.id.contacts};
SimpleCursorAdapter contacts =
new SimpleCursorAdapter(mContext, R.layout.activity_contact_row, activity, from, to);
setListAdapter(contacts);
}
return inflater.inflate(R.layout.activity_contact_list, container, false);
}
}
… So here only Contact1 is showing up in the layout. Or whichever column I have first. From what I understood reading was that I didn’t have to utilize a for loop to correctly bind all of the columns, but it seems that you do? Unless I’m missing something here. Any help would be appreciated.
You have only one item (
R.id.contacts) inside your arrayto; therefore only one view is used/displayed for the data. You need to add the Ids for the other views, too.