-1

アプリケーションに、ImageViewとオプションでオーバーレイTextViewで構成されるカスタムビューが必要です。これらを組み合わせて単一のビューを作成するにはどうすればよいですか?ビューを使用してGridViewまたはListViewにアイテムを入力する予定なので、単一のビューが必要です。複合コントロールを使用する最良の方法はありますか?これはアダプターとGridViewでうまく機能しますか?

4

1 に答える 1

1

他のレイアウトと同じように作成し、そのレイアウトをグリッドビューのアダプターで使用するだけです。

Java コード:

Cursor scheduleCursor = mDbHelper.fetchAllSchedules();
startManagingCursor(scheduleCursor);

String[] from = new String[] { ScheduleDBAdapter.SCHEDULE_MACHINE,
    ScheduleDBAdapter.SCHEDULE_PRIORITY,
    ScheduleDBAdapter.SCHEDULE_RUNPART,
    ScheduleDBAdapter.SCHEDULE_RUNJOB,
    ScheduleDBAdapter.SCHEDULE_OPERATOR,
    ScheduleDBAdapter.SCHEDULE_NXTJOB1,
    ScheduleDBAdapter.SCHEDULE_NXTPRT1,
    ScheduleDBAdapter.SCHEDULE_NXTJOB2,
    ScheduleDBAdapter.SCHEDULE_NXTPRT2 };
int[] to = new int[] { R.id.txtMachine, R.id.txtPriority,
    R.id.txtRunningPart, R.id.txtRunningJob, R.id.txtOperator,
    R.id.txtNextJobNumber1, R.id.txtNextJobPart1,
    R.id.txtNextJobNumber2, R.id.txtNextJobPart2 };
SimpleCursorAdapter schedule = new SimpleCursorAdapter(this,
    R.layout.customgrid, scheduleCursor, from, to);

GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(schedule);

カスタムグリッド.xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:shrinkColumns="*"
    android:stretchColumns="*" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center" >

        <TextView
            android:id="@+id/txtMachine"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000000"
            android:gravity="left"
            android:text="machine" />

        <TextView
            android:id="@+id/txtPriority"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ff0000"
            android:gravity="center"
            android:text="priority"
            android:textColor="#000000" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center" >

        <TextView
            android:id="@+id/txtRunningPart"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_span="2"
            android:background="#000000"
            android:gravity="center"
            android:text="part #"
            android:textColor="#009900" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center" >

        <TextView
            android:id="@+id/txtRunningJob"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_span="2"
            android:background="#000000"
            android:gravity="center"
            android:text="job #"
            android:textColor="#009900" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow4"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center" >

        <TextView
            android:id="@+id/txtOperator"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_span="2"
            android:background="#000000"
            android:gravity="center"
            android:text="operator"
            android:textColor="#0000FF" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow5"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center" >

        <TextView
            android:id="@+id/txtNextJobPart1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000000"
            android:gravity="center"
            android:text="part #"
            android:textColor="#FFFF00" />

        <TextView
            android:id="@+id/txtNextJobNumber1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000000"
            android:gravity="center"
            android:text="job #"
            android:textColor="#FFFF00" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow6"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center" >

        <TextView
            android:id="@+id/txtNextJobPart2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000000"
            android:gravity="center"
            android:text="part #"
            android:textColor="#FFFF00" />

        <TextView
            android:id="@+id/txtNextJobNumber2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000000"
            android:gravity="center"
            android:text="job #"
            android:textColor="#FFFF00" />
    </TableRow>

</TableLayout>

そして、ここでそれが実行されています:

ここに画像の説明を入力

于 2012-06-17T14:55:08.713 に答える