フラグメントに表示されるリストビューがあります。画面の下部にボタンがあり、押すとWebサービスを呼び出して追加のデータを取得します。追加のデータがある場合は、リストビューに追加する必要があります。私はこのフォーラムや他の多くのWebサイトを検索して、その方法を見つけようとしましたが、成功しませんでした。どんな助けでも大歓迎です。
次のXMLレイアウトでフラグメントを定義するのではなく、動的にフラグメントを追加する必要があるのではないかと考えています。
ListFragmentを使用して、画面上のリストビューを膨らませています。
2つのフラグメントが表示された画面があります。画面のXMLは次のとおりです。-
<LinearLayout 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:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<fragment
android:name="atos.mobilereporting.com.ReportList"
android:layout_width="323dp"
android:layout_height="match_parent" />
<fragment
android:name="atos.mobilereporting.com.ReportDetail"
android:layout_width="958dp"
android:layout_height="match_parent" />
</LinearLayout>
<Button
android:id="@+id/getReports"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Refresh Mobile Reports" />
</LinearLayout>
ビューを膨らませるコードは次のとおりです。-
public class ReportList extends ListFragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get list of reports...
repList = ReportDefinitionFactory.buildReportList(3);
activity = getActivity();
ListAdapter la = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1,
ReportDefinitionFactory.getReportDescriptions(repList));
setListAdapter(la);
}
}
このコードは、3行の単純なリストビューを示しています。
ここから行くのかわからないので、この時点でやめなければなりません。リストビューを最初に作成するために使用される配列に行を追加するコードがありますが、リストビューで更新を呼び出す方法がわかりません。
ありがとう
マーティン