当前位置: 动力学知识库 > 问答 > 编程问答 >

datagrid - Is there any Data Grid control available for android?

问题描述:

I am looking for including a pre-built data grid control in a data-driven to display data in a tabular form just like we do in desktop or web applications. I am aware that there are alternate ways available just like we have it here:

How to create a DataGrid display in android?

Any other good alternate?

网友答案:

I wrote one. It supports image buttons, text view and edit text. Clicking on a column header will sort the data. Also a column can be set as clickable. If interested I can send you my code.

Here is a sample layout file using the code.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:tg="http://schemas.android.com/apk/res/com.ra.music"
xmlns:pc="http://schemas.android.com/apk/res/com.ra.music"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MusicActivity" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/music_header" />

<com.ra.playercontrol.PlayerControl
    android:id="@+id/player_control"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    pc:editSong="true" />

<ScrollView
    android:id="@+id/table_scroll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:isScrollContainer="true"
    android:scrollbars="vertical|horizontal" >

    <com.ra.tablegrid.TableGrid
        android:id="@+id/music_table"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:stretchColumns="*" >

        <com.ra.tablegrid.TableTextView
            android:id="@+id/song_id"
            tg:fieldName="song_id"
            tg:keyField="true"
            tg:visible="false" />

        <com.ra.tablegrid.TableImageButton
            android:id="@+id/play_song"
            android:src="@drawable/play_button_up"
            tg:displayOrder="02"
            tg:fieldName="play_song"
            tg:down_src_table="@drawable/play_button_down" />

        <com.ra.tablegrid.TableImageButton
            android:id="@+id/edit_song"
            android:src="@drawable/edit_button_up"
            tg:displayOrder="03"
            tg:fieldName="edit_song"
            tg:down_src_table="@drawable/edit_button_down" />

        <com.ra.tablegrid.TableImageButton
            android:id="@+id/delete_song"
            android:src="@drawable/delete_button_up"
            tg:displayOrder="04"
            tg:fieldName="delete_song"
            tg:down_src_table="@drawable/delete_button_down" />

        <com.ra.tablegrid.TableTextView
            android:id="@+id/song_name"
            android:textSize="16sp"
            tg:clickable="true"
            tg:displayOrder="07"
            tg:fieldName="song_name"
            tg:sortable="true"
            tg:fieldPercent="0.26"
            tg:title="@string/song_name" />

        <com.ra.tablegrid.TableTextView
            android:id="@+id/artist"
            android:textSize="13sp"
            tg:displayOrder="10"
            tg:fieldName="artist"
            tg:secondarySorts="song_name"
            tg:sortable="true"
            tg:fieldPercent="0.13"
            tg:title="@string/artist" />

        <com.ra.tablegrid.TableTextView
            android:id="@+id/cd_name"
            android:textSize="13sp"
            tg:displayOrder="15"
            tg:fieldName="cd_name"
            tg:secondarySorts="song_name"
            tg:sortable="true"
            tg:fieldPercent="0.14"
            tg:title="@string/cd_name" />

        <com.ra.tablegrid.TableTextView
            android:id="@+id/category"
            android:textSize="13sp"
            tg:displayOrder="20"
            tg:fieldName="category"
            tg:secondarySorts="qualifier1,qualifier2,song_name"
            tg:sortable="true"
            tg:fieldPercent="0.08"
            tg:title="@string/category" />

        <com.ra.tablegrid.TableTextView
            android:id="@+id/qualifier1"
            android:textSize="13sp"
            tg:displayOrder="25"
            tg:fieldName="qualifier1"
            tg:secondarySorts="qualifier2,song_name"
            tg:sortable="true"
            tg:fieldPercent="0.10"
            tg:title="@string/qualifier1" />

        <com.ra.tablegrid.TableTextView
            android:id="@+id/qualifier2"
            android:textSize="13sp"
            tg:displayOrder="30"
            tg:fieldName="qualifier2"
            tg:secondarySorts="song_name"
            tg:sortable="true"
            tg:fieldPercent="0.14"
            tg:title="@string/qualifier2" />

        <com.ra.tablegrid.TableTextView
            android:id="@+id/length"
            android:textSize="13sp"
            tg:displayOrder="35"
            tg:fieldName="length"
            tg:sortable="true"
            tg:fieldPercent="0.08"
            tg:title="@string/length" />
    </com.ra.tablegrid.TableGrid>
</ScrollView>

And here is a code snipet for implementing the table.

    mTableGrid.setInitialSort("song_name", true);
    mTableGrid.setOnTableClickListener(new ITableClickListener() {
        @Override
        public void onTableClick(String columnName, String keyValue) {
            MusicActivity.this.onTableClick(columnName, keyValue);
        }
    });


    private void populateTable(ArrayList<DisplaySong> displaySongs) {
    mTableGrid.clearData();
    for (DisplaySong song : displaySongs) {
        mTableGrid.addDataRow(createTableDataRow(song));
    }
    mTableGrid.buildTable();
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: