Question

I am developing an Android application. I implemented a View Pager with Tabs, as described in this link, with a FragmentStatePagerAdapter, and adding the tabs to the ActionBar on the OnCreate method of the Activity.

On my onCreateView event of my frament, I am inflating a layout that contains an EditText View, so each generated Tab has its own EditText for the user to enter data.

The thing is, I currently need to locally store the content of each textbox once its been fully filled with the input the user is writing in each EditText control. For example, I can know that the user is finished entering data, when they change the tab, or unfocus the control.

SCENARIO 1: I tried attaching a TextWatcher to the EditText control in my onCreateView event of the fragment, but it didn't work for me because I don't need it to be called every time a letter is inserted in my control, so I discarded that option

SCENARIO 2: I tried attaching a OnEditorActionListener to the EditText control in my onCreateView event of the fragment, but it's never called (like this link explains)

SCENARIO 3: I was thinking of handling the onTabUnselected event of the TabListener, but I don't know how to access the PREVIOUS EditText control value. Besides, that will only work when the user selects the tab by pressing its header, but not on the swipe event. In that case I am attanching a SimpleOnPageChangeListener to the ViewPager, but again, in that context, I can't know which was the previous Tab, nor can I access its EditText control.

What can I do? Thank you very much!

Was it helpful?

Solution

When the EditText lose focus, you simply need to add focusChangedListener to the EditText:

OnFocusChangeListener focus = new OnFocusChangeListener() {

@Override
public void onFocusChange(View v, boolean hasFocus) {
    // TODO Auto-generated method stub

   }
};

Every time the edit text lose focus just add the data to a singleton class that holds all of the data, from all of the TextEdits, check this out

android get value from all fragment tab

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top