I am developing a motivational app that has different words.txt/texts.txt files for each day i.e 365 files.
i have stored every .txt files in my project’s assets folder and refference it to appear in a textview. which i will like users to read different files/topics per day:
a. I will like to to develop the app in a way that each message(text file) of the day will
be shown to the user automatically after the splash screen, without the user having
to navigate to the message of the day.
But when i run the app it shows blank
see my code below
public class MainActivity extends ActionBarActivity {
private NavDrawerListAdapter adapter;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private CharSequence mDrawerTitle;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mTitle;
private ArrayList<NavDrawerItem> navDrawerItems;
private TypedArray navMenuIcons;
private String[] navMenuTitles;
private void displayView(final int selection) {
Fragment fragment = null;
switch (selection) {
case 0: {
fragment = new FragmentDailyDevotion();
break;
}
case 1: {
fragment = new FragmentBibleInAYear();
break;
}
case 2: {
fragment = new FragmentBookmarks();
break;
}
case 3: {
fragment = new FragmentAboutAuthor();
break;
}
case 4: {
fragment = new FragmentVideos();
break;
}
case 5: {
fragment = new FragmentAudio();
break;
}
case 6: {
fragment = new FragmentGlossary();
break;
}
case 7: {
fragment = new FragmentMoreInformation();
break;
}
case 8: {
fragment = new FragmentNeedHelp();
break;
}
}
if (fragment != null) {
final android.support.v4.app.FragmentManager fragmentManager = this.getSupportFragmentManager();
fragmentManager.popBackStack((String)null, 1);
fragmentManager.beginTransaction().replace(R.layout.daily_devotion, fragment).addToBackStack((String)null).commit();
this.mDrawerList.setItemChecked(selection, true);
this.mDrawerList.setSelection(selection);
this.setTitle("MyApp");
this.mDrawerLayout.closeDrawer((View)this.mDrawerList);
}
}
}
public class FragmentDailyDevotion extends Fragment
{
String DevotionTitle;
Context ThisContext;
//private View$OnClickListener btnListener;
Calendar c;
private DatePickerDialog dialog;
Fragment fragment;
ImageButton imgBookmark;
ImageButton imgBookmarked;
ImageButton imgCalendar;
ImageButton imgNext;
ImageButton imgPrev;
ImageButton imgSettings;
ImageButton imgShare;
TextView lblDate;
TextView lblText;
TextView lblTitle;
int mDay;
int mMonth;
int mYear;
ScrollView scrMiddle;
public FragmentDailyDevotion() {
super();
this.ThisContext = null;
this.fragment = null;
this.c = Calendar.getInstance();
this.dialog = null;
/*this.btnListener = (View$OnClickListener)new View$OnClickListener() {
public void onClick(final View view) {
if (view == FragmentDailyDevotion.this.lblDate) {
FragmentDailyDevotion.this.ShowCalendar();
}
if (view == FragmentDailyDevotion.this.imgPrev) {
FragmentDailyDevotion.this.DoPrevious();
}
if (view == FragmentDailyDevotion.this.imgNext) {
FragmentDailyDevotion.this.DoNext();
}
if (view == FragmentDailyDevotion.this.imgCalendar) {
FragmentDailyDevotion.this.ShowCalendar();
}
if (view == FragmentDailyDevotion.this.imgBookmark) {
FragmentDailyDevotion.this.DoBookmark();
}
if (view == FragmentDailyDevotion.this.imgBookmarked) {
FragmentDailyDevotion.this.DoUnbookmark();
}
if (view == FragmentDailyDevotion.this.imgShare) {
final Intent intent = new Intent();
final String getShareDevotionText = GlobalV.GetShareDevotionText(FragmentDailyDevotion.this.mMonth, FragmentDailyDevotion.this.mDay, FragmentDailyDevotion.this.mYear, FragmentDailyDevotion.this.DevotionTitle);
intent.setAction("android.intent.action.SEND");
intent.setType("text/plain");
intent.putExtra("android.intent.extra.TEXT", getShareDevotionText);
FragmentDailyDevotion.this.startActivity(Intent.createChooser(intent, (CharSequence) ("Share " + GlobalV.globalAppName)));
}
if (view == FragmentDailyDevotion.this.imgSettings) {
FragmentDailyDevotion.this.fragment = new FragmentSettings();
FragmentDailyDevotion.this.ShowNewFragment();
}
}
};*/
}
/*public void ShowCalendar() {
if (this.dialog == null) {
this.dialog = new DatePickerDialog(this.ThisContext, (DatePickerDialog$OnDateSetListener)new PickDate((PickDate)null), this.mYear, this.mMonth, this.mDay);
}
this.dialog.show();
}*/
public void ShowNewFragment() {
if (this.fragment != null) {
this.getFragmentManager().beginTransaction().replace(R.id.lblText, this.fragment).addToBackStack((String)null).commit();
}
}
public String getTextFile(final int n, final int n2) {
String s = null;
switch (n) {
default: {
s = "devotion/january" + Integer.toString(n2);
break;
}
case 0: {
s = "devotion/january" + Integer.toString(n2);
break;
}
case 1: {
s = "devotion/february" + Integer.toString(n2);
break;
}
case 2: {
s = "devotion/march" + Integer.toString(n2);
break;
}
case 3: {
s = "devotion/april" + Integer.toString(n2);
break;
}
case 4: {
s = "devotion/may" + Integer.toString(n2);
break;
}
case 5: {
s = "devotion/june" + Integer.toString(n2);
break;
}
case 6: {
s = "devotion/july" + Integer.toString(n2);
break;
}
case 7: {
s = "devotion/august" + Integer.toString(n2);
break;
}
case 8: {
s = "devotion/september" + Integer.toString(n2);
break;
}
case 9: {
s = "devotion/october" + Integer.toString(n2);
break;
}
case 10: {
s = "devotion/november" + Integer.toString(n2);
break;
}
case 11: {
s = "devotion/december" + Integer.toString(n2);
break;
}
}
return s.trim();
}
public String loadTextFile(final InputStream inputStream) throws IOException {
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final byte[] array = new byte[4096];
while (true) {
final int read = inputStream.read(array);
if (read <= 0) {
break;
}
byteArrayOutputStream.write(array, 0, read);
}
return new String(byteArrayOutputStream.toByteArray(), "UTF8");
}
public void loadWebView(final int n, final int n2, final int n3) {
this.ShowDateHeader();
}
public View onCreateView(final LayoutInflater layoutInflater, final ViewGroup viewGroup, final Bundle bundle) {
final View inflate = layoutInflater.inflate(R.layout.daily_devotion, viewGroup, false);
this.ThisContext = (Context)this.getActivity();
if (GlobalV.globalGlossaryYear != 0 && GlobalV.globalGlossaryMonth != 0 && GlobalV.globalGlossaryDay != 0) {
this.mYear = GlobalV.globalGlossaryYear;
this.mMonth = GlobalV.globalGlossaryMonth;
this.mDay = GlobalV.globalGlossaryDay;
GlobalV.globalGlossaryYear = 0;
GlobalV.globalGlossaryMonth = 0;
GlobalV.globalGlossaryDay = 0;
GlobalV.globalSelectedYear = this.mYear;
GlobalV.globalSelectedMonth = this.mMonth;
GlobalV.globalSelectedDay = this.mDay;
}
else if (GlobalV.globalSelectedYear != 0 && GlobalV.globalSelectedMonth != 0 && GlobalV.globalSelectedDay != 0) {
this.mYear = GlobalV.globalSelectedYear;
this.mMonth = GlobalV.globalSelectedMonth;
this.mDay = GlobalV.globalSelectedDay;
}
else {
this.mYear = this.c.get(Calendar.YEAR);
this.mMonth = this.c.get(Calendar.MONTH);
this.mDay = this.c.get(Calendar.DAY_OF_MONTH);
}
this.scrMiddle = (ScrollView)inflate.findViewById(R.id.scrMiddle);
(this.lblText = (TextView)inflate.findViewById(R.id.lblText)).setText((CharSequence) "");
//(this.lblDate = (TextView)inflate.findViewById(R.id.lblDate)).setOnClickListener(this.btnListener);
this.lblTitle = (TextView)inflate.findViewById(R.id.lblTitle);
/*(this.imgPrev = (ImageButton)inflate.findViewById(R.id.imgPrev)).setOnClickListener(this.btnListener);
(this.imgNext = (ImageButton)inflate.findViewById(R.id.imgNext)).setOnClickListener(this.btnListener);
(this.imgCalendar = (ImageButton)inflate.findViewById(2131361818)).setOnClickListener(this.btnListener);
(this.imgBookmark = (ImageButton)inflate.findViewById(2131361819)).setOnClickListener(this.btnListener);
(this.imgBookmarked = (ImageButton)inflate.findViewById(2131361820)).setOnClickListener(this.btnListener);
(this.imgShare = (ImageButton)inflate.findViewById(2131361821)).setOnClickListener(this.btnListener);
(this.imgSettings = (ImageButton)inflate.findViewById(2131361822)).setOnClickListener(this.btnListener);*/
this.DoSettings();
this.prepWebView();
return inflate;
}
public void prepWebView() {
this.ShowDateHeader();
}
/*private class PickDate implements DatePickerDialog$OnDateSetListener
{
public void onDateSet(final DatePicker datePicker, final int mYear, final int mMonth, final int mDay) {
FragmentDailyDevotion.this.mYear = mYear;
FragmentDailyDevotion.this.mMonth = mMonth;
FragmentDailyDevotion.this.mDay = mDay;
if (mYear != GlobalV.globalDevotionYear) {
GlobalV.AssetDialog("Invalid Year Selected. Only Year " + GlobalV.globalDevotionYear + " is permitted", FragmentDailyDevotion.this.ThisContext).create().show();
}
else {
FragmentDailyDevotion.this.loadWebView(mMonth, mDay, mYear);
}
}
}*/
}
Kindly help