In TabLayout
there are 4 tabs. At 2nd tab I have EditText
(for search).When entered some text in EditText
and when swipe to another tab again and I come back to watch EditText
, whatever I entered text which is not cleared. But I want to clear EditText
when swiped to other tab.
Asked
Active
Viewed 912 times
-4
-
what have you tried so far? post some of your code for the ViewPager / Adapter. are you already using `ViewPager.OnPageChangeListener`? – marmor Apr 04 '17 at 07:02
-
Is this a `viewpager` or 4 buttons in `horizontal linearlayout` ? – buzzingsilently Apr 04 '17 at 07:03
-
Yes I am using ViewPager.OnPageChangeListener.I have doubt that is when I swipped to another tab, onResume() or onPause() methods are not getting called. – Lokesh Apr 04 '17 at 07:05
-
No , it's viewpager @buzzingsilently – Lokesh Apr 04 '17 at 07:06
-
ok but viewpager is located in activity,but edittext is in fragment. Is it possible to change fragment's views by Activity? – Lokesh Apr 04 '17 at 07:09
-
setText("") in `onresume()` method of fragment. – buzzingsilently Apr 04 '17 at 07:12
-
@Lokeshkrishna I guess http://stackoverflow.com/questions/17845641/alternative-for-the-onresume-during-fragment-switching will help you. – buzzingsilently Apr 04 '17 at 07:18
2 Answers
0
try this in your edittext fragment..
@Override
public void setMenuVisibility(final boolean visible) {
super.setMenuVisibility(visible);
if (visible) {
}
else
{
edittext.setText("");
}
}

faisal iqbal
- 724
- 1
- 8
- 20
0
in your onResume() of the fragment clear the edittext like this.
@Override
public void onResume() {
super.onResume();
yourEditText.getText().clear(); //or yourEditText.setText("");
}

hushed_voice
- 3,161
- 3
- 34
- 66