我有一个列表片段,我用一个简单的光标适配器填充。但是,只有第一列绑定到布局。这是代码。
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);
}
}
...所以这里只有 Contact1 出现在布局中。或者我首先拥有的任何专栏。据我了解,我不必使用 for 循环来正确绑定所有列,但您似乎这样做了?除非我在这里遗漏了什么。任何帮助,将不胜感激。