In my app I have 5 fragments in home page..
I am using Relative Layout to display five fragments. I tired linear Layout also it does not work..
This is my layout code
<android.support.v4.widget.NestedScrollView xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:http="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@color/background"
android:layout_width="match_parent"
android:id="@+id/scrollView"
android:layout_height="wrap_content">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
>
<fragment android:name="com.example.Fragment1"
android:id="@+id/fragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="20dp"
tools:layout="@layout/fragment_need_card" />
<fragment android:name="com.example.Fragment2"
android:id="@+id/fragment2"
android:layout_width="match_parent"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="20dp"
android:layout_below="@+id/fragment1"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_discussion" />
<fragment android:name="com.example.Fragment3"
android:id="@+id/fragment3"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="20dp"
android:layout_below="@+id/fragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_askapro" />
<fragment android:name="com.example.Fragment4"
android:id="@+id/fragment4"
android:layout_width="match_parent"
android:focusable="true"
android:layout_below="@+id/askapro"
android:layout_height="wrap_content"
tools:layout="@layout/fragment3" />
<fragment android:name="com.example.Fragment5"
android:id="@+id/fragment5"
android:layout_width="match_parent"
android:layout_marginLeft="8dp"
android:layout_below="@+id/fragment4"
android:layout_marginBottom="20dp"
android:layout_marginRight="8dp"
android:layout_height="fill_parent"
tools:layout="@layout/recent_articles" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
by Default 2 fragments visible in screen,for next 3 fragments user has to scroll vertically..
public class Fragment3 extends BaseFragment {
public Fragment3() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v= inflater.inflate(R.layout.fragment3, container, false);
CardView b= (CardView)v.findViewById(R.id.cardview);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new Intent(getActivity(),DummyEvent.class);
startActivity(intent);
}
});
return v;
}
this onclick listener never fired first time ,i have to click twice..
I think the third fragment is not getting focused.may be i bind the fragment in layout? any one has idea to solve the problem?