一个ListView我Android新功能,我刚刚创建的SQLite数据库!我添加值(希望如此),我想在ListView中显示这些值。显示sqlite的结果要在ViewPager片段
现在更详细...我有一个ViewPager和第一个片段我有一个按钮,它触发了我的sqlite数据库的setmethod。在ViewPager的第二个片段中,我想要一个ListView,其中在按下按钮后将显示Sqlite的结果。问题是,即使我创建了ListView,它并没有显示在我的片段中。另外,当我在我的设备中运行我的代码时,应用程序崩溃并返回下面发布的错误。我会很感激,如果有人可以帮助我正确实现ListView并使其工作!
OnCreateView:
public class PeopleManager extends ListFragment {
private PeopleHelper getHelper;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.fragment_people_manager,null);
getHelper = new PeopleHelper(getActivity());
ListView list = (ListView) v.findViewById(R.id.list);
List<PeopleModel> values = new ArrayList<PeopleModel>();
ArrayAdapter<PeopleModel> adapter = new ArrayAdapter<PeopleModel>(getActivity(),
android.R.id.list, values);
setListAdapter(adapter);
return v;
}
我的xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<Button
android:id="@+id/peopleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="People List" />
</LinearLayout>
logcat的:
03-02 17:37:10.449: E/AndroidRuntime(5555): java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
我已经做到了!错误消失,但没有出现在我的ListView! – gimbo