开发者

Android switching between layout(Forms)

I 开发者_如何学Goam fairly new to the android development platform.

I am developing a small android help desk application, as a project. My problem is switching between my layouts. now there are a lot of help on the internet but could not find anything use full to my application.

I have a "main.xml" layout file and a "login.xml" layout file. I can not find a proper way to switch between the two layouts.

I though setting the context view to the other layout will work. but i keep on getting a force close message on my simulator

      setContentView(R.layout.login);

So as you can see i have an login screen and as soon as the user logged in the layout needs to change to the main layout.


In Android, you can not change the content view of the activity.

However, you can create a new activity for example LoginActivity and set its content view with setContentView(R.layout.login); and then you can switch to this layout by creating an intent which will open the new activity as below.

startActivity(new Intent (YourActivity.this, TheActivitytobeopened.class));


I have an activity with a LinearLayout. And then I dynamically add and remove views to it.

LinearLayout llMain = (LinearLayout) this.findViewById(R.id.room_layout_main);
roomView = new RoomView(this);
llMain.addView(roomView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
//use llMain.removeView(roomView) to remove it

I am pretty sure you can load views from xml but I am not sure. Hope that helps. EDIT- looks like you can load a view from xml, see here: http://www.aslingandastone.com/2011/dynamically-changing-android-views-with-xml-layouts/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜