Change framelayout View

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

Change framelayout View

Postby achie1266 » Thu Dec 10, 2009 12:19 am

How do we change the view in a framelayout?

ex: if there is a textview and a listview in a framelayout and I need to replace the listview with the textview[or bring it to the front],
how do i do it?
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Top

Postby Kur1310 » Thu Dec 10, 2009 1:10 pm

hi....
In FrameLayout, Children are drawn in a stack, with the most recently added child on top.

So u can change the order of the listview and the textview.
Whatever u want to bring on top, u should add it as a last child..
-Kur
Kur1310
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Oct 28, 2009 10:50 am

Postby achie1266 » Thu Dec 10, 2009 4:52 pm

Thank you I just saw the docs and I may have to use bringChildtofront as its already added.

I have another problem though
I tried to create a frame layout like this
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:layout_width="fill_parent"
  6.  
  7.    android:layout_height="fill_parent"
  8.  
  9.    >
  10.  
  11.     <LinearLayout  
  12.  
  13.         android:id="@+id/view_1"  
  14.  
  15.             android:orientation="vertical"
  16.  
  17.             android:layout_width="fill_parent"
  18.  
  19.             android:layout_height="fill_parent" >
  20.  
  21.                 <TextView  
  22.  
  23.                     android:layout_width="fill_parent"
  24.  
  25.                     android:layout_height="wrap_content"
  26.  
  27.                     android:text="@string/hello"
  28.  
  29.                     />
  30.  
  31.                 <Button
  32.  
  33.                         android:id="@+id/button_1"
  34.  
  35.                         android:layout_width="fill_parent"
  36.  
  37.                         android:layout_height="wrap_content"
  38.  
  39.                         android:text="Switch View to 2" />
  40.  
  41.     </LinearLayout>
  42.  
  43.     <LinearLayout    
  44.  
  45.         android:id="@+id/view_2"  
  46.  
  47.             android:orientation="vertical"
  48.  
  49.             android:layout_width="fill_parent"
  50.  
  51.             android:layout_height="fill_parent" >
  52.  
  53.                 <TextView  
  54.  
  55.                     android:layout_width="fill_parent"
  56.  
  57.                     android:layout_height="wrap_content"
  58.  
  59.                     android:text="Hi there"
  60.  
  61.                     />
  62.  
  63.                 <Button
  64.  
  65.                         android:id="@+id/button_2"
  66.  
  67.                         android:layout_width="fill_parent"
  68.  
  69.                         android:layout_height="wrap_content"
  70.  
  71.                         android:text="Switch Back" />
  72.  
  73.     </LinearLayout>
  74.  
  75. </FrameLayout>
  76.  
  77.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


I am trying to access it from the main class in this way
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.achie.test;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.os.Bundle;
  8.  
  9. import android.view.View;
  10.  
  11. import android.widget.FrameLayout;
  12.  
  13.  
  14.  
  15. public class FramesTest extends Activity {
  16.  
  17.     /** Called when the activity is first created. */
  18.  
  19.     @Override
  20.  
  21.     public void onCreate(Bundle savedInstanceState) {
  22.  
  23.         super.onCreate(savedInstanceState);
  24.  
  25.         setContentView(R.layout.main);
  26.  
  27.        
  28.  
  29.         FrameLayout fLayout = (FrameLayout)findViewById(R.layout.main);
  30.  
  31.         fLayout.findViewById(R.id.view_1).setVisibility(View.VISIBLE);
  32.  
  33.         fLayout.findViewById(R.id.view_2).setVisibility(View.INVISIBLE);
  34.  
  35.     }
  36.  
  37. }
  38.  
  39.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


It gives a nullPointerException at the lines
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. fLayout.findViewById(R.id.view_1).setVisibility(View.VISIBLE);
  2.  
  3. fLayout.findViewById(R.id.view_2).setVisibility(View.INVISIBLE);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


why is it not grabbing the layout from the xml file?/ what am I doing wrong?

thank you.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby Kur1310 » Fri Dec 11, 2009 7:06 am

Ok i got the point..

once u have set the contentView to some layout, u need not to take a handle to it's root layout..
So in your code, FrameLayout fLayout = (FrameLayout)findViewById(R.layout.main);
this line is not necessary..
u can access any view in that layout using.
findViewById(R.id.view_1); instead of fLayout.findViewById(R.id.view_1);


so just remove fLayout from:
- fLayout.findViewById(R.id.view_1).setVisibility(View.VISIBLE);
- fLayout.findViewById(R.id.view_2).setVisibility(View.INVISIBLE);
-Kur
Kur1310
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Oct 28, 2009 10:50 am

Postby achie1266 » Fri Dec 11, 2009 5:04 pm

awesome,

Thankyou Kur1310.
that worked
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests