-3
Gentlemen I am making a registration and I chose to do using Tabs because the same is extensive ( many fields ) and involves photos, this way I can put organized information, is the registration of service order, however I noticed that Tabs is 99% to present data I did not find any example that shows its use in a registration (in my case in sqlite) and now with the screen made how to save/update this data that are in the tabs?
I believe that the logic would be to obtain the contents of the tabs (3), to save a button in the last tab? Has one of you ever done such a thing And can suggest me a way?
I tried to evolve the routine and now I have more information and codes that can exemplify what was done until then.
The logic used for a register with Tabs is that there will be a "listener" in the navigation, this will access the corresponding Fragment in viewPager and get the data for validation or persistence.
Below the listener in the mother activity, note that the process will be done by obtaining the Fragment from the previous tab
private void setupTabListener() {
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
View customView = tab.getCustomView();
if (customView != null) {
ImageView icon = (ImageView) customView.findViewById(R.id.itemImage);
int tabIconColor = ContextCompat.getColor(getApplicationContext(), android.R.color.white);
icon.setColorFilter(tabIconColor, PorterDuff.Mode.SRC_IN);
}
}
// Aba Anterior
@Override
public void onTabUnselected(TabLayout.Tab tab) {
Log.i(TAG, "onTabUnselected()" + tab.getPosition());
View customView = tab.getCustomView();
Boolean valido;
// Obter o fragment usando o adapter
if (tab.getPosition()==0){
VeiculoFragment fragment = (VeiculoFragment)
.customFragmentPageAdapter
.getItem(tab.getPosition());
// Na execução do método do fragment abaixo ocorre um erro
fragment.isValid();
}
}
}
@Override
public void onTabReselected(TabLayout.Tab tab) {}
});
}
Error occurs and captured the stack
Process: br.com.tecnico, PID: 19927
java.lang.NullPointerException
at br.com.tecnico.fragment.VeiculoFragment.isValid(VeiculoFragment.java:143)
at br.com.tecnico.atividades.InstalacaoActivity$1.onTabUnselected(InstalacaoActivity.java:158)
at android.support.design.widget.TabLayout.dispatchTabUnselected(TabLayout.java:1170)
at android.support.design.widget.TabLayout.selectTab(TabLayout.java:1153)
at android.support.design.widget.TabLayout.selectTab(TabLayout.java:1127)
at android.support.design.widget.TabLayout$Tab.select(TabLayout.java:1426)
at android.support.design.widget.TabLayout$TabView.performClick(TabLayout.java:1536)
The line where the error occurs is in Fragment that was instantiated and called the isValid() method, the error occurs in if(edtNumero.gettext())
class VeiculoFragment extends BaseFragment {
@Override
public boolean isValid() {
// O Erro ocorre neste if abaixo
if (edtNumero.getText().toString().trim().equals("")){
//mostraSnackErro(getResources().getString(R.string.erro_frota_vazia));
return false;
}
if (edtModelo.getText().toString().trim().equals("")){
//mostraSnackErro(getResources().getString(R.string.erro_modelo_vazio));
return false;
}
I updated giving more information and codes
– Robson