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

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

问题描述

我猜它真的很简单,可能是列表视图或片段中的设置.但是我现在几个小时都找不到解决方案.所以..我有一个这样的列表视图

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();

如果我单击列表上的项目,整个列表将替换为由一个按钮和几个文本字段组成的片段 (*).Fragment 使用有关项目的信息正确替换了 listView.当我按回时,它确实正确地将列表视图带回来.

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?

推荐答案

我认为问题在于 replace 方法没有替换 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天全站免登陆