安卓:创建活动,并多次使用不同的数据 [英] Android : Create an activity and use it many times with different data

查看:102
本文介绍了安卓:创建活动,并多次使用不同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序是这样的:一开始我有这导致MainActivity其中有3个片段的LoginActivity。在第一个片段我有8项的列表视图。列表视图中的每一项都是可点击的。我想,如果我想我可以去到另一个活动通过点击列表视图的项目之一。

My app goes like this: At the beginning i have the LoginActivity which leads to MainActivity which has 3 fragments. In the first fragment i have a listview with 8 items. Each item of the listview is clickable. I suppose that if i want i can go to another activity by clicking one of the listview's item.

我的问题是,如果我只能创建一个活动,而不是把8,当我点击任何一个列表视图项,每次启动这个活动有不同的数据。

My Question is if i can create only one activity instead of making 8 and when i click any of the listview items, to start this activity with different data every time.

通过不同的数据我的意思是:该活动将具有相同的布局(可扩展列表视图),但一些游戏等会有所不同。

By different data i mean : This activity will have the same layout (expandable listview) but some of the titles etc will be different..

推荐答案

下面是你可以尝试

1)在单次活动有这样的布局

1) In Single Activity have this Layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <fragment
        android:id="@+id/listFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_marginTop="?android:attr/actionBarSize"
        android:layout_weight="2"
        class="Your package Name" />

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2" 
        android:id="@+id/frameLayout">
    </FrameLayout>

</LinearLayout> 

这个布局包含一个片段,将包含您的ListFragment 而注:第二个即的FrameLayout用于你想在单击ListView项的动态添加您的浏览

This Layout contains one Fragment which will contain your ListFragment And 2nd one i.e FrameLayout is used to Dynamically add your View you want on Click of ListView item

2)这2语句将帮助你弹出你认为这可能会覆盖在对方

2) This 2 statement will help you to pop your view which may get overlayed on each other

getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
fragmentTransaction.addToBackStack(null);

希望这可以帮助...

Hope this could help...

这篇关于安卓:创建活动,并多次使用不同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆