I am trying to make an information app that has multiple navigable pages in Android Studio. I will probably have around 40 or so pages of information. I was wondering whether I should manually create an activity for each and every page (with headers, images, and info) or to use one activity and programmatically add textviews and imageviews in accordance with a String.
I decided to first try using only one activity, and it's working alright, but to add new features like different fonts to emphasize words or titles or to add formulas would require a lot more complicated code.
For example I would have this in my string.xml file.
<string name="page1">
~Introduction~\n
Hi guys!\n
`image`
</string>
And then I would have a method called updatePage() that checks for my markers like ~ for titles and ` for images.
private void updatePage(int pPageNum){
String dayString = "";
pageNum = pPageNum;
mScrollView.fullScroll(ScrollView.FOCUS_UP);
mEditor.putInt("page", pageNum);
mEditor.apply();
//todo add substrings to look for specific image and formula markers
try{
dayString = dayJSON.getString(pPageNum+"");
pageInfoLL.removeAllViews();
int i = 0;
int t = 0;
int nonTextStartIndex = 0;
int nonTextEndIndex = 0;
while(i != -1 || t == 3){
if(dayString.contains("`")){
nonTextStartIndex = dayString.indexOf("`");
String textSubstring = dayString.substring(0, nonTextStartIndex);
if(!textSubstring.equals("")){
addTextViewToLayout(pageInfoLL, textSubstring, 12);
dayString = dayString.substring(nonTextStartIndex + 1);
}
nonTextEndIndex = dayString.indexOf("`");
String imageName = dayString.substring(0, nonTextEndIndex);
Log.e("IMAGERESOURCENAME", imageName);
addImageToLayout(pageInfoLL, imageName);
dayString = dayString.substring(nonTextEndIndex+1);
Log.e("After Image String", dayString);
if(dayString.equals("")){
Log.e("String Finished", "STRING FINISHED");
i = -1;
}
t++;
}else{
addTextViewToLayout(pageInfoLL, dayString, 12);
i = -1;
}
}
}catch (JSONException je){
je.printStackTrace();
makeToast("JSON Error, Page Did Not Update Successfully.");
}catch (NullPointerException ne){
ne.printStackTrace();
makeToast("NULL Error, Page Did Not Update Successfully.");
}
}
As you can see though, it removes a lot of the flexibility. I also wanted to add formulas using jqMath, but jqMath uses lots of characters that overlap with other uses. The logistics just becomes a lot more complicated. Thus, I want to know just what are the advantages to doing it the wya Im doing it right now. If it's only a smaller app file size then maybe I'll just manually make each page. Thanks for the help.