Thursday 15 April 2010

java - Android- Adding items dynamically to scrollview -


I was for hours to comply with various tutorials to add dynamically objects Scrolwu, but some Not working too. ..

This idea is only for adding strings to a checkbox, which was done in a separate XML file and I want to increase the list as I add them. To

Now, only a string to be added (to change this last one), and any attempt to try to change my app stops working The code is as it stands:

  Add a table layoutplayablelayout; Tablerock Table 1; ScrollView AdwareScrollView; String [] players = new string [] ( "blah", "whatever", "test", "Nifa!"}; @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet) ; AddPlayersTableLayout = (Table layout) findViewById (R.id.TableLayout1); TableRow1 = (Tablerote) Find VVBIID (R.DTABRO1); AddPlayersScrollView = (ScrollView) (Find theViewById); Render.ViewById (R.id.playersScrollView); insertPlayerInScrollView ();} < / Code>  

The function to add items here has been implemented: (add_player_row.xml is that file, jah Not Tekstwu and box must be items)

  private void Insert Player PlayerScrollView () {LayoutInflater inflator = (LayoutInflater) getSystemService (reference. LEOUT_INFLATER_SERVICE); NewPlayerRow See inflator.inflate (R.layout ;add_player_row, tap); TextView newPlayerTextView = (text view) newPlayerRow.findViewById (R.id.addPlayerTextView); Check box player checkbox = (checkbox) Find VVBID (RID Player Checkbox); newPlayerTextView.setText (players [1]); AddPlayersTableLayout.addView (newPlayerRow, 0); }   

The last line of code is the only way on which it works at all, although on most forums and tutorials people will give me the signal to use addPlayersScrollView, but if I do this If the app crashes ... any thoughts? Thanks a lot!

I'm facing something similar to you. I have a layout like this:

  Android: ScrollView Android: layout_width = "match_parent" Android: layout_height = "match_parent" & gt; & Lt; TableLayout Android: id = "@ + id / tablelayoutlist" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" /> & Lt; / Scrollview & gt;   

and my line is defined as (mRowLayout.xml):

  & lt; TableRow xmlns: android = "http://schemas.android com / apk / res / android" android: id = "@ + id / linearLayoutRow" Android: layout_width = "match_parent" Android: layout_height = "match_parent" & gt; & Lt; Checkbox Android: id = "@ + id / checkboxServEmail" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" /> & Lt; / TableRow & gt;   

And then I use the following code to keep my line up:

  Private Zero fillTable (see V, cursor C) {TableLayout Ll = (TableLayout) v.findViewById (R.id.tableLayoutList); MTableRow = Null; Int i = 0; While (! C.isAfterLast ()) {i ++; See MTableRow = (tablerows). Float (getActivity (), R.Lay Out.MR Lowlight, empty); Check box CB = (checkbox) mTableRow.findViewById (R.id.checkBoxServEmail); Cb.setText (c.getString (c.getColumnIndex (Empleado.EMAIL)); MTableRow.setTag (i); // Add TableRows to TableLayout ll.addView (mTableRow); C.moveToNext (); }}   

What I'm trying to do here is to increase my rows dynamically. The cursor has the items that I want to show with the data base. I'm not sure this can solve your problem. let me know.

No comments:

Post a Comment