Update Layout at RUNTIME depending on user interaction?

Put your problem here if it does not fit any of the other categories.

Update Layout at RUNTIME depending on user interaction?

Postby mingang » Thu Apr 03, 2008 8:50 am

Hi,

Are there any tutorials or links to help me solve the following issue:

Objective: To display different EditText boxes for user input depending on SPINNER selection

Prerequisites(alrdy done)
a) Design of RelativeLayout via the xml file
b) Possible SPINNER selection: 1) Lat/Long, 2) Address
c) OnItemSelectedListener to listen for user selection

Problems faced
a) When i tried to remove to remove the two EditText boxes below the SPINNER, the other VIEWS( spinner, textview ) below the EditText boxes loses their layout.



Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <EditText android:id="@+id/latitude"
  2.  
  3.         android:layout_width="100dip"
  4.  
  5.        android:layout_height="wrap_content"
  6.  
  7.                 android:layout_below="@id/spinner_search_mode"
  8.  
  9.                 android:layout_marginRight="10dip"
  10.  
  11.                 android:layout_marginBottom="10dip"
  12.  
  13.                 android:textSize="13px"
  14.  
  15.                 android:text="@string/latitude"/>
  16.  
  17.     <EditText android:id="@+id/longitude"
  18.  
  19.         android:layout_width="100dip"
  20.  
  21.        android:layout_height="wrap_content"
  22.  
  23.        android:layout_toRight="@id/latitude"
  24.  
  25.        android:layout_alignBaseline="@id/latitude"
  26.  
  27.        android:textSize="13px"
  28.  
  29.        android:text="@string/longitude"/>
  30.  
  31.        
  32.  
  33.     <!-- Additional Search Options -->    
  34.  
  35.     <TextView android:id="@+id/search_add_options"
  36.  
  37.        android:layout_width="wrap_content"
  38.  
  39.        android:layout_height="wrap_content"
  40.  
  41.        android:layout_marginBottom="15dip"
  42.  
  43.        android:textStyle="italic"
  44.  
  45.        android:text="@string/search_add_options"
  46.  
  47.        android:layout_below="@id/latitude"/>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


Questions:
a) Is it possible to change the above
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:layout_below="@id/latitude"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
for the TextView search_add_options at runtime to other values? (So that i can add new EditText boxes and assign the TextView to be below these new EditText)
Attachments
Debug.jpg
ScreenShot
Debug.jpg (20.22 KiB) Viewed 639 times
mingang
Freshman
Freshman
 
Posts: 2
Joined: Thu Apr 03, 2008 8:28 am

Top

Postby Jesmiatka » Thu Apr 03, 2008 9:19 am

What about the following solution:
You always have those boxes in the XML layout and just play with their Visibility

For Example:
You want to hide the 2 boxes
Depending on how you want to handle the UI

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  box1.setVisibility(View.GONE);
  2.  
  3. box2.setVisibility(View.GONE);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

OR
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  box1.setVisibility(View.INVISIBLE);
  2.  
  3. box2.setVisibility(View.INVISIBLE);
Parsed in 0.029 seconds, using GeSHi 1.0.8.4


Toggeling them back would be:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. box1.setVisibility(View.VISIBLE);
  2.  
  3. box2.setVisibility(View.VISIBLE);
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Postby mingang » Thu Apr 03, 2008 9:47 am

Hi, Thanks for the reply.

I'hv tried BOXA.setVisibility(BOXA.GONE) before, and the effect is similar to when i called RelativeLayout.removeView(BOXA).

Ideally, it is hoped to be able to know how to manipulate(add, remove) the VIEWs in the RelativeLayout via code for flexibility.

However, ya the effect of BOXA.setVisibility(BOXA.INVISIBLE) looks alright. I'll try in the time being to work with this solution. Thanks. :D
mingang
Freshman
Freshman
 
Posts: 2
Joined: Thu Apr 03, 2008 8:28 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests