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();
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?
Best way of calling Activity from Fragment class is that make interface in Fragment and add onItemClick() method in that interface. Now implement it to your first activity and call second activity from there.
Add a fragment to an activity You can add your fragment to the activity's view hierarchy either by defining the fragment in your activity's layout file or by defining a fragment container in your activity's layout file and then programmatically adding the fragment from within your activity.
Fragments introduce modularity and reusability into your activity's UI by allowing you to divide the UI into discrete chunks. Activities are an ideal place to put global elements around your app's user interface, such as a navigation drawer.
A Fragment is not an Activity.
I solved a similar problem by adding android:clickable="true"
in the element that was behaving as if it was "transparent". Making it clickable made sure the click events were handled by it instead of passed to the views bellow.
So, I had exactly the same issue, I still don't know the reason why, but make sure your adding the android:clickable="true" to the roovView of your 2nd fragment's layout.
something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:clickable="true" android:orientation="vertical"> .....any content for your item (2nd fragment)..... </LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With