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

Apps Table Layout Listener

Discussion in 'Android Development' started by sehudson, May 22, 2011.

  1. sehudson

    sehudson Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    Feb 2, 2011

    Feb 2, 2011
    17
    0
    15
    I have a Table Layout, that I am dynamically adding rows to.

    In my code, I created an array of TableRows that is of size = to the number of rows in my Cursor (database results).

    So as I walk through the cursor while loop, I create a new Table Row, whose index is my position in the cursor.

    Code (Text):
    1.  
    2. trArray[rowCount] = new TableRow(this);
    3. //add data to the row
    4. tableLayout.addView(trArray[rowCount])
    5.  
    The table displays fine but I am trying to add a Listener to each row, but I cannot figure out how to find out which row the user clicked.

    Any Ideas? The problem is that I cannot use the RowCount value because at the time that they click on the row, RowCount is no longer what it was when the row was created, since the table has been created, rowCount now has a value of the total # of Rows.

    Is there a getSelectedRow or something similar that I can use on an onClickListener for the TableLayout?
     

    Advertisement

  2. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    What are you trying to develop? It sounds like you should use ListView instead
     
  3. sehudson

    sehudson Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    Feb 2, 2011

    Feb 2, 2011
    17
    0
    15
    can you put multiple 'columns' in a listview?
     
  4. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    You can put almost what ever you want in a listview. All you gotta do is to design the row in the listview yourself. Search on google for listview tutorials or examples.
     

Share This Page

Loading...