1. Download our Official Android App: Forums for Android!

Apps list with multiple items in one row

Discussion in 'Android Development' started by sionut, Apr 6, 2011.

  1. sionut

    sionut Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Apr 6, 2011

    Apr 6, 2011
    1
    0
    5
    Hi,

    I am trying to figure out how to create a List that contains multiple items on one row. What I want is to have a ListActivity and put multiple buttons on the same row (at least 2), depending on the space available on the device's screen. The user should be able to click/select any of the items in one row.

    I need a list because I will get the data from the database through a Cursor (I will implement a CursorAdapter for that, accessing my local SQLite db)

    All the examples that I've seen so far have only one item per row, so if anybody can give me such an example/explain what's needed, I would be grateful.

    Thank you,
    Ionut
     

    Advertisement

  2. RazzleFnDazzle

    RazzleFnDazzle Well-Known Member
    Rank:
    None
    Points:
    58
    Posts:
    123
    Joined:
    Sep 30, 2010

    Sep 30, 2010
    123
    15
    58
    I'm not sure if this is the best way, but this is how I would do it off the top of my head (I'm also not hugely familiar with all of android). You can create a separate layout for your components

    buttons.xml
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <LinearLayout android:orientation="horizontal">
    4.  <Button android:id="@+id/one"/>
    5. <Button android:id="@+id/two"/>
    6. </LinearLayout>
    7.  
    Then in your main layout create a ListView called list. Then create your own custom adapter such as an ArrayAdapter that takes R.id.list as its resource and then on getView fill in the listeners with the buttons and/or text
     

Share This Page

Loading...