I need to create a Stepper in my application that got the library on GitHub link
I was able to implement the application, however I want to put a Toolbar to inflate a menu and have the button go back into it, but I am not able to put it in the application. Here are the codes:
Xml screen 1:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarSessao2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView"
style="@style/FundoAPP"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbarSessao2"
android:layout_gravity="right">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1">
<TextView
style="@style/titleHints"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hint_sessao_1" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
android:paddingTop="24dp">
<EditText
android:id="@+id/JN_04_01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:hint="@string/hintHora"
android:textColorHint="#ffa3a3a3" />
</android.support.design.widget.TextInputLayout>
<View style="@style/Divider" />
<TextView
android:id="@+id/textView4"
style="@style/Textos"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
android:paddingTop="24dp"
android:text="@string/Repet" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Screen 2 looks like this above ...
This is the fragment of this screen above:
public class sessao_fragment1 extends stepperFragment implements View.OnClickListener{
public sessao_fragment1(){
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(
R.layout.sessao1, container, false);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_jn_04_sessao, menu);
}
@Override
public boolean onNextButtonHandler() {
return true;
}
@Override
public void onClick(View v) {
}
}
The second screen is also the same ...
And this is the screen that controls the Stepper:
public class stepper_sessao extends progressMobileStepper implements View.OnClickListener{
List<Class> stepperFragmentList = new ArrayList<>();
@Override
public List<Class> init() {
stepperFragmentList.add(sessao_fragment1.class);
stepperFragmentList.add(sessao_fragment2.class);
return stepperFragmentList;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarSessao2);
toolbar.setTitle(R.string.title_activity_inserir_programacao);
toolbar.setTitleTextColor(getResources().getColor(R.color.colorTextButton));
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Set an OnMenuItemClickListener to handle menu item clicks
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// Handle the menu item
switch (item.getItemId()) {
case R.id.manutencao_sessoes:
startActivity(new Intent(getApplicationContext(), jn_14_manutencao_sessao.class));
break;
case R.id.cad_Remedio:
startActivity(new Intent(getApplicationContext(), jn_03_remedio.class));
break;
case R.id.salvarSessao:
//SALVAR();
break;
}
return true;
}
});
toolbar.inflateMenu(R.menu.menu_jn_04_sessao);
}
@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
return super.onCreateView(parent, name, context, attrs);
}
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
return super.onCreateView(name, context, attrs);
}
@Override
public void onStepperCompleted() {
showCompletedDialog();
}
protected void showCompletedDialog(){
android.support.v7.app.AlertDialog.Builder alertDialogBuilder = new android.support.v7.app.AlertDialog.Builder(
stepper_sessao.this);
// set title
/*alertDialogBuilder.setTitle("Hooray");
alertDialogBuilder
.setMessage("We've completed the stepper")
.setCancelable(true)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
}
});
*/
// create alert dialog
android.support.v7.app.AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
//finish();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
The toolbar I posted is commented on this last screen, but it was not correct ... if they can help!
This is the error:
02-14 23:05:48.443 1354-1354/com.housepharm E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.housepharm, PID: 1354
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.housepharm/com.housepharm.Visao.Tela.stepper_sessao}: java.lang.NullPointerException