この質問はおそらくこれまでに 100 回尋ねられていることはわかっていますが、まだ問題を解決できていません。2 つのフラグメントで構成される 1 つのアクティビティがあります。1 つのフラグメントは、データベースに情報を追加するフォームです。
**R.layout.fragment_add_server:**
<?xml version="1.0" encoding="utf-8"?>
...
<LinearLayout
android:id="@+id/nameLinear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" >
<TextView
android:id="@+id/nameText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="70"
android:text="@string/strName"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/editName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="30"
android:hint="@string/editName" />
</LinearLayout>
...
そして、単なるリストビューである別のフラグメント。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/georgeback"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="60" >
</ListView>
<Button
android:id="@+id/connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/connectBTN" />
</LinearLayout>
そのフラグメント、リストビュー、データベースにあるものをすべて入力し、新しいものが追加されたときに自動更新したい(まだその段階に達していない)。以下の次のコードを使用している場合、データだけではなく、リストビューにフラグメント全体を入力することができます (つまり、リストボックス、ボタンなどが表示され、それらと対話することもできます。Inception.)。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_select_server,
container, false);
Cursor mNotesCursor = mDbHelper.fetchAllNotes();
String[] from = new String[]{mDbHelper.KEY_TITLE};
int[] to = new int[]{R.id.editName};
mCurAdapter = new SimpleCursorAdapter(view.getContext(),R.layout.fragment_add_server,mNotesCursor,from,to,0);
mMyListView=(ListView)view.findViewById(R.id.listView1);
mMyListView.setAdapter(mCurAdapter);
return view;
}
コンストラクターの from フィールドと to フィールドで何か間違ったことをしていると思います。データベース内のデータだけでなく、フラグメントビュー全体を出力として取得する理由は何ですか? 他の提案はありますか?