I guess I'll fail to explain the issue because it is WEIRD.
I need an app similar to online tutorials,the basic functionality is to switch among the pages(fragments in my case) and the content should read out.
So, I've followed Mr.Tamada " - The life saviour" tutorials The TTS and Fragments and I've merged them both.
Motto is to read the data in fragments.
Code:
public class TopRatedFragment extends Fragment implements TextToSpeech.OnInitListener
{
private static TextToSpeech tts;
TextView tv;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_top_rated, container, false);
tv = (TextView) rootView.findViewById(R.id.tv);
tts = new TextToSpeech(getActivity(), TopRatedFragment.this);
speakOut();
return rootView;
}
@Override
public void onInit(int status)
{
if (status == TextToSpeech.SUCCESS)
{
int result = tts.setLanguage(Locale.US);
tts.setSpeechRate(0);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "Language is not supported");
} else {
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed");
}
}
@Override
public void onDestroy()
{
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
private void speakOut()
{
tts.speak(tv.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
Log.e("root ", tv.getText().toString());
}
}
The text in textview is reading out. But the text of 1st fragment is read in 2nd fragment that too only when I swipe backward.
fragment 3 --> fragment 2 (here fragment 1 text is read).
I really do not understand what is happening.
And when I open the app from recently opened apps list then it is reading its own text.
Kindly help if possible....Thank you..