0

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!

Community
  • 1
  • 1
Nicole
  • 1,356
  • 3
  • 21
  • 41
  • What is the problem with text watcher again?cause you have after text change method there.. – Gigalala Jun 03 '14 at 16:04
  • Pretty sure this is exactly what you are looking for. Determine when the EditText has lost focus and set your text accordingly. http://stackoverflow.com/questions/10627137/how-can-i-know-when-a-edittext-lost-focus – zgc7009 Jun 03 '14 at 16:10
  • Gigalala: the "after text change" event is called 1 time per entered letter, not when the full text is entered. For example: If I write "Hello" it will be called 1 time for the H, another for the "e" another for the "l" and so on.. check this link: http://developer.android.com/reference/android/text/TextWatcher.html – Nicole Jun 03 '14 at 16:24
  • Yeah, so use that method and compare the length of the new text to your maximum number of lines your EditText is set to ask for. – Cruceo Jun 03 '14 at 18:55
  • That's not going to work since I don't have a maximum number of lines or of characters for that matter. There's no way for me to know which character will be the last inside my method – Nicole Jun 03 '14 at 19:14
  • I am kinda confused, how do you know when the user is done typing?when he release the keyboard? if so you are looking for focus, if its by the amount of letters or anything else, you need to validate text with text watcher...i dont think there is any other option, unless i didn't understand what you want. – Gigalala Jun 03 '14 at 19:17
  • Another thing you can make a "done" button on keyboard, or just a button. – Gigalala Jun 03 '14 at 19:20
  • Please read my 3rd option, there I explain the context in which the EditText is located. I have multiple tabs and each one have a EditText, so when the user changes the tab, I could retrieve the value that was on the EditText of the previous tab, but I don't know how to do that – Nicole Jun 03 '14 at 19:34
  • Ok, so the sign for you that the text is "ready" for you to read it, is that the user changed tabs? – Gigalala Jun 03 '14 at 19:37
  • Yes. That could be an option! – Nicole Jun 03 '14 at 19:38

1 Answers1

0

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

Community
  • 1
  • 1
Gigalala
  • 439
  • 1
  • 8
  • 24
  • As I posted in my question, I don't know how to access the PREVIOUS EditText from that event, because if I access the EditBox by ID it brings me the EditText of the current tab, not the previous one. Resuming, the question is how I do the "manage all the textEdits here" – Nicole Jun 03 '14 at 19:56