changing XML ContentView by button clicks.

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

changing XML ContentView by button clicks.

Postby KanedaSyndrome » Tue Dec 09, 2008 9:08 pm

Someone PLEASE show me how to do this..

I am imagining a XML layout with a button on it, once you click it you get a new XML layout.

And please don't tell me to look around the board, I have done this 100 times now and still found nothing to this specific problem.

I am hoping for someone to respond with a way to do this (remember to test it before posting it, because I had an idea to do this and it didn't work for some reason).

So basically something that does this:

XMLfile1 with a button in it.

user clicks button.

XMLfile2 loads.
KanedaSyndrome
Developer
Developer
 
Posts: 41
Joined: Tue Nov 11, 2008 3:32 pm

Top

Re: changing XML ContentView by button clicks.

Postby worry » Wed Dec 10, 2008 1:03 am

The same thing!

I have one.xml with textinput. Then I want on button click to load two.xml with list of contats. I want a user to select a contact and application should send sms with text, typed in one.xml.

Any ideas?
worry
Junior Developer
Junior Developer
 
Posts: 16
Joined: Fri Nov 28, 2008 12:06 am

Postby MrSnowflake » Wed Dec 10, 2008 12:00 pm

[mod]This is not a tutorial, come on people, you do know what tutorials are, don't you? I have to move tons of posts every day, because they are in the Tutorials section where they should be in some coding problem section!

Why not do: user clicks button 1 then do setContentView(R.layout.layout2)?
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby worry » Wed Dec 10, 2008 2:09 pm

MrSnowflake wrote:[mod]This is not a tutorial, come on people, you do know what tutorials are, don't you? I have to move tons of posts every day, because they are in the Tutorials section where they should be in some coding problem section!

Why not do: user clicks button 1 then do setContentView(R.layout.layout2)?


I don't know why, but if I add new xml (with simple basic syntax) to eclipse project, even if I do not use it, the program starts with error.

And another thing, as soon as android apps are intent based, may be it is proper to create new intent for this kind of staff (for each new layout and functionallity you are going to use)?
worry
Junior Developer
Junior Developer
 
Posts: 16
Joined: Fri Nov 28, 2008 12:06 am

Postby MrSnowflake » Wed Dec 10, 2008 2:16 pm

worry wrote:
MrSnowflake wrote:Why not do: user clicks button 1 then do setContentView(R.layout.layout2)?


I don't know why, but if I add new xml (with simple basic syntax) to eclipse project, even if I do not use it, the program starts with error.
Then why don't you look up the error? Check your log.

worry wrote:And another thing, as soon as android apps are intent based, may be it is proper to create new intent for this kind of staff (for each new layout and functionallity you are going to use)?
You could also use a viewAnimator, which allows you to animate between Views, but this is not nescessairy.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby KanedaSyndrome » Wed Dec 10, 2008 2:57 pm

hey I get the same.

I tried to do the onclicklistener on a button, in the code to execute I put a simple "setContentView", that works fine if you are refering to a button in your current XML layout, but once you are in the new layout (layout 2) the buttons don't work.

Also, I get an error as well, and I have brought this up in the past without anyone finding an answer to it.

So that's why I was thinking that SOMEONE might be able to do the very simple "layout 1" click button and go to "layout2" click button in layout2 and get back to "layout1" again.

Something simple like that would make me extremely happy.. If someone could just do that without asking questions or suggesting something I have already tried and that I found didn't work :(


I tried having all button listeners in the main class, this bugged the program and it wouldn't run at all.

You can check my code in this thread I made here: switching_layout_from_button_clicks-t3561.html
KanedaSyndrome
Developer
Developer
 
Posts: 41
Joined: Tue Nov 11, 2008 3:32 pm

Top

Postby MrSnowflake » Wed Dec 10, 2008 3:14 pm

Start using ViewAnimators, those will make your life easier.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby KanedaSyndrome » Wed Dec 10, 2008 3:19 pm

can you hint how to use them? I am not sure how to go about it -.-
KanedaSyndrome
Developer
Developer
 
Posts: 41
Joined: Tue Nov 11, 2008 3:32 pm

Postby MrSnowflake » Wed Dec 10, 2008 3:23 pm

Very simple: you can just add view (which you inflate first) and then you can select which one you want to see, don't know the appropriate method names, but the docs should make those clear.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby worry » Thu Dec 11, 2008 5:58 am

MrSnowflake wrote:Very simple: you can just add view (which you inflate first) and then you can select which one you want to see, don't know the appropriate method names, but the docs should make those clear.


Actually, docs for android API are very stupid, they do not have any class usage examples, just description (Compare this to MSDN). So, any chance you know a link with example of how ViewAnimators works?


Also, where can I find error logs? Even if I run Debug, Eclipse just says 'source not found', when "force application close" occurs. It does not say what resource not found, or in which line of my code this error occurs. Just 'source not found', it is ridiculous.

For example, this is simplest program:

I have xxx.test package, which contain two files:
test1.java, test2.java with main.xml and main2.xml

test1 uses layout from main.xml
test2 uses layout from main2.xml
I want to run test2 from test


test1.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package xxx.test;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.content.*;
  6.  
  7. public class test1 extends Activity {
  8.     /** Called when the activity is first created. */
  9.     @Override
  10.     public void onCreate(Bundle savedInstanceState) {
  11.         super.onCreate(savedInstanceState);
  12.         setContentView(R.layout.main);
  13.        
  14.         Intent myIntent = new Intent();
  15.         myIntent.setClassName("xxx.test", "test2");
  16.        startActivity(myIntent);
  17.        
  18.        
  19.     }
  20. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


test2.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package xxx.test;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5.  
  6. public class test2 extends Activity {
  7.     /** Called when the activity is first created. */
  8.     @Override
  9.     public void onCreate(Bundle savedInstanceState) {
  10.         super.onCreate(savedInstanceState);
  11.         setContentView(R.layout.main2);
  12.     }
  13. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


main.xls
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    >
  7. <TextView  
  8.    android:layout_width="fill_parent"
  9.    android:layout_height="wrap_content"
  10.    android:text="@string/hello"
  11.    />
  12. </LinearLayout>
  13.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4



main2.xls
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    >
  7. <TextView  
  8.    android:layout_width="fill_parent"
  9.    android:layout_height="wrap_content"
  10.    android:text="@string/hello2"
  11.    />
  12. </LinearLayout>
  13.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


It just produce an error after it runs: the application test stopped unexpectedly. I have no clue..
worry
Junior Developer
Junior Developer
 
Posts: 16
Joined: Fri Nov 28, 2008 12:06 am

Postby MrSnowflake » Thu Dec 11, 2008 9:32 am

worry wrote:
MrSnowflake wrote:Very simple: you can just add view (which you inflate first) and then you can select which one you want to see, don't know the appropriate method names, but the docs should make those clear.
Actually, docs for android API are very stupid, they do not have any class usage examples, just description (Compare this to MSDN). So, any chance you know a link with example of how ViewAnimators works?
first of all, try finding something in MSDN, it's 10 times harder as finding something in the android docs. The documentation is a lot more clear, though, indeed, no code examples, but there are a LOT examples in the samples dir, including a demonstration of a ViewAnimator.

worry wrote:Also, where can I find error logs? Even if I run Debug, Eclipse just says 'source not found', when "force application close" occurs. It does not say what resource not found, or in which line of my code this error occurs. Just 'source not found', it is ridiculous.
In cmd type: "adb logcat". Then you get to see the whole callstack.

worry wrote:For example, this is simplest program:

I have xxx.test package, which contain two files:
test1.java, test2.java with main.xml and main2.xml

test1 uses layout from main.xml
test2 uses layout from main2.xml
I want to run test2 from test

.....

It just produce an error after it runs: the application test stopped unexpectedly. I have no clue..
Like I (and many other) have said thousands of times: When you see "The application stopped unexpectedly" CHECK YOUR LOG!
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests