gpt4 book ai didi

java - ListFragment,不显示数据

转载 作者:行者123 更新时间:2023-12-01 13:41:58 28 4
gpt4 key购买 nike

我试图让我的 ListFragment 显示在我的 View 中,但是我对这段代码遇到了无穷无尽的问题,无法让它显示我的解析器的结果。我相信这很可能是我的 xml 文件的问题,我的代码中没有收到任何错误,它只是不显示 ListView。

activity_main.xml

}

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >


<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
class="com.example.CourseList">

</ListView>
</RelativeLayout>

list_layout.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"
android:orientation="vertical" >

<TextView
android:id="@+id/course"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="36sp" />

<TextView
android:id="@+id/room"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/course"
android:layout_alignBottom="@+id/course"
android:layout_marginLeft="16dp"
android:layout_toRightOf="@+id/course"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceSmall" />

<TextView
android:id="@+id/building"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/room"
android:layout_alignBottom="@+id/room"
android:layout_toRightOf="@+id/room"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>

最佳答案

我相信您需要调用onViewCreated。尝试更改这行代码:

     @Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
int num = getArguments().getInt(ARG_SECTION_NUMBER);
records = dao.getAllRecords();
mAdapter = new TimetableAdapter(getActivity(), android.R.id.list, records);
listView.setAdapter(mAdapter);
}

对此:

   @Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
int num = getArguments().getInt(ARG_SECTION_NUMBER);
records = dao.getAllRecords();
mAdapter = new TimetableAdapter(getActivity(), android.R.id.list, records);
listView.setAdapter(mAdapter);
}

关于java - ListFragment,不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20663465/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com