开发者

android separate view on button press

i am developing an android todo list app to learn. right now in my main layout xml file, i list all to-do list items. i created a menu button called add to add a new to-do开发者_如何学C. the problem is that i want to show a different view when add button is pressed. in that view i will have an editbox and 2 buttons. anyone have any suggestion on how that can be accomplished?


For this scenario it will be better to create two activities: a ListActivity for the to-do list and an edit activity. You can switch between the two activites with an Intent.


You can have two FrameLayouts on the same view file. By default the frame holding the ListView will be shown, and once the user needs the add/edit view you switch to the 2nd frame populating the desired fields.

This is better than having two Activities because you don't have to wait the loadtime of the 2nd new Activity each time which can take long if you work on multiple records on the same sessions.


You can follow above options, but if you want to do it with only a single activity then also you can do it. You just need to do one thing, You can create two XML layout for your view. One for the List and anotoer for the Add/Edit controls. You can use the serContentView method of the activity to change the view wheveer you required. If you are developing a small application then this will also be a good option to do it. It will also gives you the same feeling like using to saperate activities and also it will avoid to work with multiple activities for same group of functionality. using this option your application will work with only single activity.


Pentium10, what code would you need to switch between views? Would the following layout xml be suitable:

<FrameLayout 
android:id="@+id/page1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
    android:text="Page 1"
    android:textSize="24sp"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:gravity="center"/>
</FrameLayout>
<FrameLayout 
android:id="@+id/page2" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
    android:text="Page 2"
    android:textSize="24sp"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:gravity="center"/>
</FrameLayout>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜