私はいくつかの調査を行いましたが、良い例は見つかりませんでした。フラグメントのカスタムレイアウトを使用して、カーソルからGridViewを作成する方法
現在の設定:
ArrayList<String> arrCursor = new ArrayList<String>();
List<mydata> md = mydatabase.getthedata("1");
for (mydata cn1 : md) {
arrCursor.add(cn1.getTheFirst());
arrCursor.add(cn1.getTheSecond());
}
ArrayAdapter arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, arrCursor);
gv.setAdapter(arrayAdapter); //the gridview
GridViewのレイアウト:
<FrameLayout 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"
tools:context="com.myapp.chao">
<GridView
android:id="@+id/gvalldata"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="auto_fit"
android:gravity="center"
android:stretchMode="columnWidth"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp" />
</FrameLayout>
上記だけの単純なリストではなく、カスタム1を表示します。
カスタムアダプタ・プロセスを開始するには、私はアイテムリストのレイアウトを設定している:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvfirst"
android:layout_marginBottom="10dp"
android:gravity="center"
android:textSize="25dp" />
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvsecond" />
</LinearLayout>
にはどうすればアイテムリストレイアウトを使用してGridViewコントロールを表示し、ボックスになりますカスタムアダプタを追加することができます。私が探しています何
:これは、カスタムアダプタを作る仕事をし
gv.setAdapter(新しいCustomAdapter(これ、prgmNameList、prgmImages))をGridViewのためにそのアダプタを設定する必要があり
例が見つかりました:http://www.appsrox.com/android/tutorials/showcase/8/ ... – Si8
'ArrayAdapter'はあなたのアプリケーションで動作しますが、代わりに' CursorAdapter'を使用することをお勧めします。データセットの反復処理や配列へのコピーが不要になります。はるかに効率的で、notifyDataSetChanged()がアダプタで呼び出されたときにすぐにデータを更新します。 [Here](https://github.com/codepath/android_guides/wiki/Populating-a-ListView-with-a-CursorAdapter)はその例です。 –
@GaryBakそれはうまくいくかもしれません。私はそれをテストしています。ありがとう。 ListViewの代わりに私はGridViewを使用しています。 – Si8