質問

How would you make the following user interface (see the picture below)?

The UI always has 3 columns, and many rows.
Pressing any button1 saves the data of its respective row in memory.
Pressing any button2 deletes the data in its respective row.

I am still undecided between a gridview and a listview, and quite confused how to code at this time (in particular the onClicklistener). Thank you in advance for any help.

I am planning to use

役に立ちましたか?

解決

you can use a listview with a custom list item which has a linearlayout with the other views inside

custom list tutorials:

http://www.vogella.com/tutorials/AndroidListView/article.html

http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/

example custom list item:

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

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/layout2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/layout2"
    android:text="Data: " 
    android:gravity="center|left"
    android:textSize="16sp"/>

<LinearLayout
    android:id="@+id/layout2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>

</RelativeLayout>

他のヒント

you can use a table layout for such look and feel. see this example .and this also.

Table layout is useful because you can define easily how many columns and rows you want in your view. and after then you can easily place widgets in that.

// Try this way,hope this will help you to solve your problem...

Note : i think you have to use "ListView" with custom adapter.,"ListView" more convenient for less or more no data.

**list_item.xml**

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.50"
        android:gravity="center_vertical">
        <TextView
            android:id="@+id/textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Data"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.50">
        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button1"/>
        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button2"/>
    </LinearLayout>
</LinearLayout>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top