I am trying to validate fragment on swipe.
but it gives me error on logcat- Exception dispatching input event. Exception in MessageQueue callback: handleReceiveCallback java.lang.NullPointerException
Here is my activityclass
screen = this;
// Initilization
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getActionBar();
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
getActionBar().setDisplayHomeAsUpEnabled(true);
viewPager.setAdapter(mAdapter);
actionBar.setHomeButtonEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
/*actionBar.setSelectedNavigationItem(position);*/
inc_fragment = new Incomefragment();
boolean isValid;
canSwipe = inc_fragment.canSwipe();
if(canSwipe.matches("false")){
isValid = false;
}
else
isValid = true;
int currentPosition = 0;
// <-- here, you need to check yourself valid or not
if (!isValid) {
viewPager.setCurrentItem(currentPosition);
}else{
viewPager.setCurrentItem(position);
currentPosition = position;
}
}
@Override
public void onPageScrolled(int pos, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int pos) {
}
});
and here is my fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
context = getActivity().getApplicationContext();
rootView = inflater.inflate(R.layout.tab1, container, false);
income_salary = (EditText) rootView.findViewById(R.id.salary_income_t);
return rootView;
}
public String canSwipe()
{
registerUiWidgets(rootView);
String swipable = "";
if(inc_sal.matches(""))
{
swipable = "false";
}
else
swipable = "true";
return swipable;
}
public void registerUiWidgets(View v)
{
//this line is throwing error what should i do?
inc_sal = income_salary.getText().toString();
System.out.println("Income from salary is:"+inc_sal);
}
//Excuse me for text mistakes
I have also googled ([like this] (How to validate EditText in Fragments and prevent Fragment change?) ) but not find much about this.