点击片段调用它后面的活动 [英] clicking on the fragment invokes activity behind it

查看:117
本文介绍了点击片段调用它后面的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林猜测它很简单的东西,在列表视图或片段,也许一个设置。
但我想不出现在发现了几个小时,它的解决方案。
所以..
我有这样一个ListView

Im guessing its something really simple, maybe a setting in listview or fragment. But I couldnt find solution for it for couple of hours now. So.. I have a listView like this

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true">

<ListView 
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#fffafa"
    />

</RelativeLayout>

当有人点击列表项。我有这样一个片段取代它

when someone clicks on the list item. I replace it with a fragment like this

    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction ft = manager.beginTransaction();
    ft.replace(R.id.content, newFragment);

    ft.addToBackStack(null);
    ft.commit();

如果我点击在列表中的项目,整个列表被替换由一个按钮,和几个文本字段的片段(*)。
该片段与有关项目的信息正确代替ListView中。当我preSS回到它正常带给列表视图回来了。

If I click on the item on the List, The whole list is replaced with a fragment(*) consisting of a Button and and couple of text fields. The Fragment replaces the listView properly with information about the item. When I press back it does properly bring the list view back.

问题是,如果我在的背景点击*它的行为就好像我会点击这是它背后的名单上..并带来片段有关该项目的前面。我可以无休止地背景点击带来其他片段。我可以通过单击回来,回来挖回列表..

The problem is that if i click on the background of the * it behaves as if I would click on the list that is behind it.. and brings fragment about that item to the front. I can click endlessly on background to bring other fragments. I can dig back to list by clicking back,back..

为什么这个片段是透明的?我该如何解决这个问题?

Why this fragment is transparent? how can i fix this?

推荐答案

我认为问题是,替换方法并不能取代的ListView 。它仅替换是容器内的其它片段。在这种特殊情况下有没有。因此,你基本上添加您的片段上的的ListView顶部因为 RelativeLayout的允许的看法是对的顶部另一个。当你点击的片段,你不能完全处理它,所以它经过到这是的ListView基本视图

I believe the issue is that the replace method doesn't replace the ListView. It only replaces other fragments that are within the container. In this specific case there are none. Thus, you're essentially adding your fragment on top of the ListView because the RelativeLayout allows views to be on top of one another. When you click on the fragment, you're not fully handling it, so it goes through to the base view which is the ListView.

有一个简单,快捷,和肮脏的解决方案是检索的ListView 对象,无论是从容器自行删除或设置它的能见度 GONE 。一个更好的解决办法是使用 ListFragment 应显示预期的结果。

A simple, quick, and dirty solution would be to retrieve the ListView object and either remove it from the container yourself or set it's visibility to GONE. A better solution would be to use ListFragment which should show the expected results.

这篇关于点击片段调用它后面的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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