I found awesome form stepper indicator library on github which can be used as beautiful form stepper indicator in Android.
I am using in the one of my application and i found its gives a beautiful looks to UI and enhance your User Interaction and User Experience.
Today i am sharing my workaround with you using of beautiful form stepper indicator.
First of all this library works with ViewPager
and shows remaining and competed steps according the Views/Fragments sets to the ViewPager
1. Adding maven repo url to your project level dependencies.
1 2 3 4 5 6 |
allprojects { repositories { maven { url 'https://jitpack.io' } } |
2. Adding form stepper indicator library to your app level dependencies.
1 |
compile 'com.github.badoualy:stepper-indicator:1.0.7' |
After syncing the project dependencies, You are ready to write Activity and Fragments code.
3. BecomePartnerActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
package com.codezlab.biketaxiuser.activities; import android.os.Bundle; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.app.Fragment; import android.support.v4.view.ViewPager; import android.widget.Toast; import com.badoualy.stepperindicator.StepperIndicator; import com.codezlab.biketaxiuser.R; import com.codezlab.biketaxiuser.customwidgets.NonSwipeableViewPager; import com.codezlab.biketaxiuser.fragments.BePartnerStepOneFragment; import com.codezlab.biketaxiuser.fragments.BePartnerStepThreeFragment; import com.codezlab.biketaxiuser.fragments.BePartnerStepTwoFragment; public class BecomePartnerActivity extends BaseToolbarActivity implements BePartnerStepOneFragment.OnStepOneListener, BePartnerStepTwoFragment.OnStepTwoListener, BePartnerStepThreeFragment.OnStepThreeListener { /** * The {@link android.support.v4.view.PagerAdapter} that will provide * fragments for each of the sections. We use a * {@link FragmentPagerAdapter} derivative, which will keep every * loaded fragment in memory. If this becomes too memory intensive, it * may be best to switch to a * {@link android.support.v13.app.FragmentStatePagerAdapter}. */ private SectionsPagerAdapter mSectionsPagerAdapter; /** * The {@link ViewPager} that will host the section contents. */ private NonSwipeableViewPager mViewPager; private StepperIndicator stepperIndicator; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_become_partner); setToolbarBackVisibility(true); setTitle("Become Partner"); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); stepperIndicator = findViewById(R.id.stepperIndicator); stepperIndicator.showLabels(false); stepperIndicator.setViewPager(mViewPager); // or keep last page as "end page" stepperIndicator.setViewPager(mViewPager, mViewPager.getAdapter().getCount() - 1); // /*// or manual change indicator.setStepCount(3); indicator.setCurrentStep(2); */ } @Override protected int getLayoutResource() { return R.layout.activity_become_partner; } /* @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_become_partner, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } */ /** * A {@link FragmentPagerAdapter} that returns a fragment corresponding to * one of the sections/tabs/pages. */ public class SectionsPagerAdapter extends android.support.v4.app.FragmentPagerAdapter { public SectionsPagerAdapter(android.support.v4.app.FragmentManager fm) { super(fm); } @Override public android.support.v4.app.Fragment getItem(int position) { // getItem is called to instantiate the fragment for the given page. // Return a PlaceholderFragment (defined as a static inner class below). switch (position) { case 0: return BePartnerStepOneFragment.newInstance("", ""); case 1: return BePartnerStepTwoFragment.newInstance("", ""); case 2: return BePartnerStepThreeFragment.newInstance("", ""); } return null; } @Override public int getCount() { // Show 3 total pages. return 3; } @Override public CharSequence getPageTitle(int position) { switch (position) { case 0: return "First Level"; case 1: return "Second Level"; case 2: return "Finish"; } return null; } } @Override public void onNextPressed(Fragment fragment) { if (fragment instanceof BePartnerStepOneFragment) { mViewPager.setCurrentItem(1, true); } else if (fragment instanceof BePartnerStepTwoFragment) { mViewPager.setCurrentItem(2, true); } else if (fragment instanceof BePartnerStepThreeFragment) { Toast.makeText(this, "Thanks For Registering", Toast.LENGTH_SHORT).show(); finish(); } } @Override public void onBackPressed(Fragment fragment) { if (fragment instanceof BePartnerStepTwoFragment) { mViewPager.setCurrentItem(0, true); } else if (fragment instanceof BePartnerStepThreeFragment) { mViewPager.setCurrentItem(1, true); } } } |
acivity_become_partner.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@id/toolbar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/toolbarColor" android:minHeight="?actionBarSize" app:popupTheme="@style/AppTheme.Toolbar.Overflow" app:theme="@style/AppTheme.Toolbar"> <TextView android:id="@+id/toolbarTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:singleLine="true" android:text="" android:textColor="@android:color/white" android:textSize="18sp" android:textStyle="bold" /> </android.support.v7.widget.Toolbar> <com.badoualy.stepperindicator.StepperIndicator android:id="@+id/stepperIndicator" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/toolbar" android:layout_margin="@dimen/activity_horizontal_margin" app:stpi_stepCount="3" /> <com.codezlab.biketaxiuser.customwidgets.NonSwipeableViewPager xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/stepperIndicator" tools:context="com.codezlab.biketaxiuser.activities.BecomePartnerActivity" /> </RelativeLayout> |
BePartnerStepOneFragment.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
package com.codezlab.biketaxiuser.fragments; import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import com.codezlab.biketaxiuser.R; /** * A simple {@link Fragment} subclass. * Activities that contain this fragment must implement the * {@link BePartnerStepOneFragment.OnStepOneListener} interface * to handle interaction events. * Use the {@link BePartnerStepOneFragment#newInstance} factory method to * create an instance of this fragment. */ public class BePartnerStepOneFragment extends Fragment implements View.OnClickListener { // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM2 = "param2"; // TODO: Rename and change types of parameters private String mParam1; private String mParam2; private OnStepOneListener mListener; public BePartnerStepOneFragment() { // Required empty public constructor } /** * Use this factory method to create a new instance of * this fragment using the provided parameters. * * @param param1 Parameter 1. * @param param2 Parameter 2. * @return A new instance of fragment BePartnerStepOneFragment. */ // TODO: Rename and change types and number of parameters public static BePartnerStepOneFragment newInstance(String param1, String param2) { BePartnerStepOneFragment fragment = new BePartnerStepOneFragment(); Bundle args = new Bundle(); args.putString(ARG_PARAM1, param1); args.putString(ARG_PARAM2, param2); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_be_partner_step_one, container, false); } private Button nextBT; @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); nextBT = view.findViewById(R.id.nextBT); } @Override public void onResume() { super.onResume(); nextBT.setOnClickListener(this); } @Override public void onPause() { super.onPause(); nextBT.setOnClickListener(null); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.nextBT: if (mListener != null) mListener.onNextPressed(this); break; } } @Override public void onAttach(Context context) { super.onAttach(context); if (context instanceof OnStepOneListener) { mListener = (OnStepOneListener) context; } else { throw new RuntimeException(context.toString() + " must implement OnFragmentInteractionListener"); } } @Override public void onDetach() { super.onDetach(); mListener = null; nextBT = null; } /** * This interface must be implemented by activities that contain this * fragment to allow an interaction in this fragment to be communicated * to the activity and potentially other fragments contained in that * activity. * <p> * See the Android Training lesson <a href= * "http://developer.android.com/training/basics/fragments/communicating.html" * >Communicating with Other Fragments</a> for more information. */ public interface OnStepOneListener { //void onFragmentInteraction(Uri uri); void onNextPressed(Fragment fragment); } } |
fragment_be_partner_step_one.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.codezlab.biketaxiuser.fragments.BePartnerStepOneFragment"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/bottomLayout"> <LinearLayout android:focusable="true" android:focusableInTouchMode="true" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="@dimen/activity_horizontal_margin" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="@dimen/dimen_10" android:text="Select Language" /> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <android.support.v7.widget.AppCompatRadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="English" /> <android.support.v7.widget.AppCompatRadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/dimen_20" android:text="Hindi" /> </RadioGroup> <android.support.design.widget.TextInputLayout android:id="@id/fullNameTIL" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentRight="true"> <EditText android:id="@id/fullNameET" android:layout_width="fill_parent" android:layout_height="40.0dip" android:hint="@string/fullname" android:inputType="textCapWords" android:singleLine="true" /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:id="@id/mobileTIL" android:layout_width="fill_parent" android:layout_height="wrap_content"> <EditText android:id="@id/mobileNumberET" android:layout_width="fill_parent" android:layout_height="40.0dip" android:hint="@string/phoneno" android:inputType="number" android:maxLength="10" android:singleLine="true" android:textColor="@color/account_grey" /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:id="@+id/alternateNumberTIL" android:layout_width="fill_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/alternateNumberET" android:layout_width="fill_parent" android:layout_height="40.0dip" android:hint="@string/alternate.no" android:inputType="number" android:maxLength="10" android:singleLine="true" android:textColor="@color/account_grey" /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:id="@id/emailTIL" android:layout_width="fill_parent" android:layout_height="wrap_content"> <EditText android:id="@id/emailET" android:layout_width="fill_parent" android:layout_height="40.0dip" android:hint="@string/email_optional" android:inputType="textEmailAddress" android:maxLength="60" android:singleLine="true" android:textColor="#ff000000" /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:id="@+id/ageTIL" android:layout_width="fill_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/ageET" android:layout_width="fill_parent" android:layout_height="40.0dip" android:hint="@string/age" android:inputType="number" android:maxLength="2" android:singleLine="true" android:textColor="#ff000000" /> </android.support.design.widget.TextInputLayout> </LinearLayout> </ScrollView> <RelativeLayout android:padding="@dimen/activity_horizontal_margin" android:id="@+id/bottomLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"> <Button android:visibility="gone" android:layout_alignParentLeft="true" android:id="@+id/backBT" style="@style/AppTheme.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="@dimen/dimen_120" android:text="@string/back" android:textColor="@color/white" /> <Button android:layout_alignParentRight="true" android:id="@+id/nextBT" style="@style/AppTheme.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="@dimen/dimen_120" android:text="@string/next.lowercase" android:textColor="@color/white" /> </RelativeLayout> </RelativeLayout> |
BePartnerStepTwoFragment.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
package com.codezlab.biketaxiuser.fragments; import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import com.codezlab.biketaxiuser.R; /** * A simple {@link Fragment} subclass. * Activities that contain this fragment must implement the * {@link OnStepTwoListener} interface * to handle interaction events. * Use the {@link BePartnerStepTwoFragment#newInstance} factory method to * create an instance of this fragment. */ public class BePartnerStepTwoFragment extends Fragment implements View.OnClickListener { // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM2 = "param2"; // TODO: Rename and change types of parameters private String mParam1; private String mParam2; private OnStepTwoListener mListener; public BePartnerStepTwoFragment() { // Required empty public constructor } /** * Use this factory method to create a new instance of * this fragment using the provided parameters. * * @param param1 Parameter 1. * @param param2 Parameter 2. * @return A new instance of fragment BePartnerStepOneFragment. */ // TODO: Rename and change types and number of parameters public static BePartnerStepTwoFragment newInstance(String param1, String param2) { BePartnerStepTwoFragment fragment = new BePartnerStepTwoFragment(); Bundle args = new Bundle(); args.putString(ARG_PARAM1, param1); args.putString(ARG_PARAM2, param2); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_be_partner_step_two, container, false); } private Button backBT; private Button nextBT; @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); backBT=view.findViewById(R.id.backBT); nextBT=view.findViewById(R.id.nextBT); } @Override public void onResume() { super.onResume(); backBT.setOnClickListener(this); nextBT.setOnClickListener(this); } @Override public void onPause() { super.onPause(); backBT.setOnClickListener(null); nextBT.setOnClickListener(null); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.backBT: if (mListener != null) mListener.onBackPressed(this); break; case R.id.nextBT: if (mListener != null) mListener.onNextPressed(this); break; } } @Override public void onAttach(Context context) { super.onAttach(context); if (context instanceof OnStepTwoListener) { mListener = (OnStepTwoListener) context; } else { throw new RuntimeException(context.toString() + " must implement OnFragmentInteractionListener"); } } @Override public void onDetach() { super.onDetach(); mListener = null; backBT=null; nextBT=null; } /** * This interface must be implemented by activities that contain this * fragment to allow an interaction in this fragment to be communicated * to the activity and potentially other fragments contained in that * activity. * <p> * See the Android Training lesson <a href= * "http://developer.android.com/training/basics/fragments/communicating.html" * >Communicating with Other Fragments</a> for more information. */ public interface OnStepTwoListener { void onBackPressed(Fragment fragment); void onNextPressed(Fragment fragment); } } |
fragment_be_partner_step_two.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.codezlab.biketaxiuser.fragments.BePartnerStepOneFragment"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/bottomLayout"> <LinearLayout android:focusable="true" android:focusableInTouchMode="true" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="@dimen/activity_horizontal_margin" android:orientation="vertical"> <android.support.design.widget.TextInputLayout android:id="@+id/currentAddressTIL" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentRight="true"> <EditText android:id="@+id/currentAddressET" android:layout_width="fill_parent" android:layout_height="40.0dip" android:hint="@string/current.address" android:inputType="textCapWords" android:singleLine="true" /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:id="@+id/permanentAddressTIL" android:layout_width="fill_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/permanentAddressET" android:layout_width="fill_parent" android:layout_height="40.0dip" android:hint="@string/permanent.address" android:inputType="textCapWords" android:maxLength="10" android:singleLine="true" android:textColor="@color/account_grey" /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:id="@+id/dobTIL" android:layout_width="fill_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/dobET" android:layout_width="fill_parent" android:layout_height="40.0dip" android:hint="@string/dob" android:inputType="text" android:maxLength="10" android:singleLine="true" android:textColor="@color/account_grey" /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:id="@+id/cityTIL" android:layout_width="fill_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/cityET" android:layout_width="fill_parent" android:layout_height="40.0dip" android:hint="@string/city" android:inputType="textCapWords" android:maxLength="60" android:singleLine="true" android:textColor="#ff000000" /> </android.support.design.widget.TextInputLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="@dimen/dimen_10" android:text="Driving Licence" /> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <android.support.v7.widget.AppCompatRadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="I have" /> <android.support.v7.widget.AppCompatRadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/dimen_20" android:text="I need" /> </RadioGroup> </LinearLayout> </ScrollView> <RelativeLayout android:padding="@dimen/activity_horizontal_margin" android:id="@+id/bottomLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"> <Button android:layout_alignParentLeft="true" android:id="@+id/backBT" style="@style/AppTheme.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="@dimen/dimen_120" android:text="@string/back" android:textColor="@color/white" /> <Button android:layout_alignParentRight="true" android:id="@+id/nextBT" style="@style/AppTheme.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="@dimen/dimen_120" android:text="@string/next.lowercase" android:textColor="@color/white" /> </RelativeLayout> </RelativeLayout> |
BePartnerStepThreeFragment.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
package com.codezlab.biketaxiuser.fragments; import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import com.codezlab.biketaxiuser.R; /** * A simple {@link Fragment} subclass. * Activities that contain this fragment must implement the * {@link OnStepThreeListener} interface * to handle interaction events. * Use the {@link BePartnerStepThreeFragment#newInstance} factory method to * create an instance of this fragment. */ public class BePartnerStepThreeFragment extends Fragment implements View.OnClickListener{ // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM2 = "param2"; // TODO: Rename and change types of parameters private String mParam1; private String mParam2; private OnStepThreeListener mListener; public BePartnerStepThreeFragment() { // Required empty public constructor } /** * Use this factory method to create a new instance of * this fragment using the provided parameters. * * @param param1 Parameter 1. * @param param2 Parameter 2. * @return A new instance of fragment BePartnerStepOneFragment. */ // TODO: Rename and change types and number of parameters public static BePartnerStepThreeFragment newInstance(String param1, String param2) { BePartnerStepThreeFragment fragment = new BePartnerStepThreeFragment(); Bundle args = new Bundle(); args.putString(ARG_PARAM1, param1); args.putString(ARG_PARAM2, param2); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_be_partner_step_three, container, false); } private Button backBT; private Button nextBT; @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); backBT=view.findViewById(R.id.backBT); nextBT=view.findViewById(R.id.nextBT); } @Override public void onResume() { super.onResume(); backBT.setOnClickListener(this); nextBT.setOnClickListener(this); } @Override public void onPause() { super.onPause(); backBT.setOnClickListener(null); nextBT.setOnClickListener(null); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.backBT: if (mListener != null) mListener.onBackPressed(this); break; case R.id.nextBT: if (mListener != null) mListener.onNextPressed(this); break; } } @Override public void onAttach(Context context) { super.onAttach(context); if (context instanceof OnStepThreeListener) { mListener = (OnStepThreeListener) context; } else { throw new RuntimeException(context.toString() + " must implement OnFragmentInteractionListener"); } } @Override public void onDetach() { super.onDetach(); mListener = null; backBT=null; nextBT=null; } /** * This interface must be implemented by activities that contain this * fragment to allow an interaction in this fragment to be communicated * to the activity and potentially other fragments contained in that * activity. * <p> * See the Android Training lesson <a href= * "http://developer.android.com/training/basics/fragments/communicating.html" * >Communicating with Other Fragments</a> for more information. */ public interface OnStepThreeListener { void onBackPressed(Fragment fragment); void onNextPressed(Fragment fragment); } } |
fragment_be_partner_step_three.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.codezlab.biketaxiuser.fragments.BePartnerStepOneFragment"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/bottomLayout"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="@dimen/activity_horizontal_margin" android:focusable="true" android:focusableInTouchMode="true" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_centerVertical="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="@dimen/dimen_10" android:text="Police Verification" /> <Button style="@style/AppTheme.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:minWidth="@dimen/dimen_120" android:text="@string/upload" android:textColor="@color/white" /> </RelativeLayout> <RelativeLayout android:layout_marginTop="@dimen/dimen_20" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_centerVertical="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="@dimen/dimen_10" android:text="Driving Licence" /> <Button style="@style/AppTheme.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:minWidth="@dimen/dimen_120" android:text="@string/upload" android:textColor="@color/white" /> </RelativeLayout> <RelativeLayout android:layout_marginTop="@dimen/dimen_20" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_centerVertical="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="@dimen/dimen_10" android:text="PAN Card" /> <Button style="@style/AppTheme.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:minWidth="@dimen/dimen_120" android:text="@string/upload" android:textColor="@color/white" /> </RelativeLayout> <RelativeLayout android:layout_marginTop="@dimen/dimen_20" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_centerVertical="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="@dimen/dimen_10" android:text="Id Proof" /> <Button style="@style/AppTheme.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:minWidth="@dimen/dimen_120" android:text="@string/upload" android:textColor="@color/white" /> </RelativeLayout> </LinearLayout> </ScrollView> <RelativeLayout android:id="@+id/bottomLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:padding="@dimen/activity_horizontal_margin"> <Button android:id="@+id/backBT" style="@style/AppTheme.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:minWidth="@dimen/dimen_120" android:text="@string/back" android:textColor="@color/white" /> <Button android:id="@+id/nextBT" style="@style/AppTheme.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:minWidth="@dimen/dimen_120" android:text="@string/submit" android:textColor="@color/white" /> </RelativeLayout> </RelativeLayout> |
NonSwipeableViewPager.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
package com.codezlab.biketaxiuser.customwidgets; import android.content.Context; import android.support.v4.view.ViewPager; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.animation.DecelerateInterpolator; import android.widget.Scroller; import java.lang.reflect.Field; /** * Created by coderzlab on 16/9/17. * http://codezlab.com */ public class NonSwipeableViewPager extends ViewPager { public NonSwipeableViewPager(Context context) { super(context); setMyScroller(); } public NonSwipeableViewPager(Context context, AttributeSet attrs) { super(context, attrs); setMyScroller(); } @Override public boolean onInterceptTouchEvent(MotionEvent event) { // Never allow swiping to switch between pages return false; } @Override public boolean onTouchEvent(MotionEvent event) { // Never allow swiping to switch between pages return false; } //down one is added for smooth scrolling private void setMyScroller() { try { Class<?> viewpager = ViewPager.class; Field scroller = viewpager.getDeclaredField("mScroller"); scroller.setAccessible(true); scroller.set(this, new MyScroller(getContext())); } catch (Exception e) { e.printStackTrace(); } } public class MyScroller extends Scroller { public MyScroller(Context context) { super(context, new DecelerateInterpolator()); } @Override public void startScroll(int startX, int startY, int dx, int dy, int duration) { super.startScroll(startX, startY, dx, dy, 350 /*1 secs*/); } } } |
Thanks for reading , Hope this will guide or help a lot.
Please share and comment if you like.
You are most welcomed if you have any suggestion or idea so that we can improve this better
21 Comments
Neelam Sai
i appreciate it,,, can you please send the code 🙂
Satvinder Singh
Thanks for reading,It will be my pleasure to share Code.
Will drop you mail soon
praveen
hi please send code to manepaally.praveen@gmail.com
Temiye
This tutorial was very help.
Please kindly share code temiye92@gmail.com
fandi
bisakah Anda mengirimkan kode 🙂
Sudhakar PV
Thanks Very Much – Please Share the sample Code Sir
Ram
please share the code on chaudhary446@gmail.com
Yannick ABOH
i great work guy, this my mail yannickabohthierry@gmail.com
Abhi
share this code please
GDJ
ok tks, it’s work
manoj yadav
hello please send me code
manoj.myyadav@gmail.com
Lendirman
hai sir … please share the code on lendirman87@gmail.com
say wat
pls i need d code
seenivasan
its very nice tutorial…please send the source code s.seenivasan039@gmail.com
seenivasan
please send the code to s.seenivasan039@gmail.com
fandi
error codezlab.biketaxiuser.customwidgets.NonSwipeableViewPager
fandi
please share the code on loveprogrammer70@gmail.com
fandi
amazing, please share the code on loveprogrammer70@gmail.com
Manoj
please share the code on jangra.manoj4@gmail.com
Samy
You can send the code to my email.Thanks.
samynemepereda@gmail.com
Arush
Thanks for the beautiful code. Could you please share it on arushmohanty@gmail.com
Thanks in advance.