Problems programmatically altering the UI

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Problems programmatically altering the UI

Postby Knossos » Thu Jan 14, 2010 4:13 pm

I am trying to add rows to a table dynamically. I am having a huge amount of difficulty getting it to work though. I was hoping that someone here could save me from going insane!

I get no errors in the whole procedure. The program starts off reading the main.xml which contains a table (with a row and a textview in the row). I find the table with findViewById(). I make a row. I add a textview to the row. I add the row to the table.

The problem is that nothing actually appears. All I see is the "Loading Content" textview which is created from the XML.

None of my programmatic inserting seems to work.

Does anyone have any ideas?
Attachments
file_contents.txt
Code
(2.17 KiB) Downloaded 29 times
Knossos
Freshman
Freshman
 
Posts: 3
Joined: Thu Jan 14, 2010 4:03 pm

Top

Postby qlimax » Thu Jan 14, 2010 5:45 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. try
  2.  
  3.         {
  4.  
  5.                 TableLayout table = (TableLayout)findViewById(R.id.mainLayout);
  6.  
  7.                
  8.  
  9.                 TableRow row = new TableRow(this);
  10.  
  11.                    //     row.setLayoutParams(new LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
  12.  
  13.                        
  14.  
  15.                         TextView tv = new TextView(this);
  16.  
  17.                         tv.setText("Random text");
  18.  
  19.                 //        tv.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
  20.  
  21.                        
  22.  
  23.                         row.addView(tv);
  24.  
  25.                         table.addView(row, new LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
  26.  
  27.         }
  28.  
  29.         catch(Exception e)
  30.  
  31.         {
  32.  
  33.                 Log.i("POSPPB", e.toString());
  34.  
  35.         }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


:)
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby Knossos » Thu Jan 14, 2010 6:13 pm

Thank you so much! That fixed it!

I don't really understand why that caused a problem though.
Knossos
Freshman
Freshman
 
Posts: 3
Joined: Thu Jan 14, 2010 4:03 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google [Bot] and 5 guests