ListView and onItemClick create transparent fragment

I have a problem. I use fragment for the list view, and after the click on an item it should replace this fragment with the fragment with this particular fragment (in this case, events). It works (the fragment is shown) but it is transparent, I can see the list in the background (even though it is not clickable). How can I get rid of this weird background? The other fragment replacing with similar methods works fine, just with "onItemClick" it does this.

Here is my code:

lvEvents.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                                    long id) {
                Event currEvent = (Event) parent.getAdapter().getItem(position);
                Log.e(TAG, currEvent.getName().toString());
                replaceFragment(0, currEvent);
            }
        });

and the method:

 private void replaceFragment(int code, Event event) {
        FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
        Bundle b = new Bundle();
        b.putParcelable("event",event);

        if(code==0){
            EventViewFragment fragment = new EventViewFragment();
            fragment.setArguments(b);
            ft.replace(R.id.fragmentFrame, fragment, EventViewFragment.TAG);
        }
        ft.commit();
    }

Any ideas what might be wrong here?

Thank you in advance!

Regards,

Grzegorz


Try this .. even i faced this problem ... i went through few articles ... it was written that we can use white background in the main layout ... in a frame layout or linear layout in my case. use android:background="@color/white"

<LinearLayout
android:id="@+id/timetable_fragment"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@color/white"
android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/card_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </android.support.v7.widget.RecyclerView>
</LinearLayout>

you can can use this method then.. it replaces the current fragment... using the replace keyword..and its onto you if you want to use addtobackStack keyword to stack the fragments.

public void replaceFragment(Fragment fragment) {
    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.container, fragment)
            .addToBackStack(null)
            .commit();
}
链接地址: http://www.djcxy.com/p/30564.html

上一篇: 一个全面的电话号码验证正则表达式

下一篇: ListView和onItemClick创建透明片段