Help With Strings

Last Updated:

  1. igorski88

    igorski88 New Member

    Hello fellow android Programers. I am pretty new to Java and would like to ask for help.
    The app I am creating Is a Martial arts info app. As of now I have a splash screen. from that it goes to a list view. in the list view their are pics of the different colored belts in the Martial art. After someone clicks on a belt. they are sent to a Tabs view. 3 different tabs. Syllabus, Video and Etc. instead of creating five different tabs activity's I want to save resources by just creating a string of some sort. So when I click on the belt color I want it to set certain stings to the info of the belt and the sting will be displayed in the tabs view under the specific tab. Maybe im taking this too far. Maybe theirs an easier way. or maybe it would be better to just have a new tabs view activity per belt color.

  2. JamTheMan

    JamTheMan Well-Known Member

    well... One way to do it is by using the built in strings.xml to set it up. In that file you can can set up strings and more importantly, string-array's. you can use this to fill out the different values in each belts sub-activities. It goes something like this:

    Your list contains a certain number of belts. As a belt is clicked the listview can provide you with the position of the clicked item. Save this position in a static variable in the listview activity - say we call it selectedBeltID.

    Then android loads you tabhost activity and shows e.g. Syllabys. In there you have to fill in data about the corresponding belt. To get the right data you then load a systemResource i.e. the right string array - say there is one called syllabus_headers.

    In that string-array you input items with data corresponding to the belt id's. So if e.g. the black belt is the first in your listview, then the first item in all the arrays should be about the black belt etc.

    Then, when Syllabus needs to fill data into, in this case, its header textview, the text is loaded from the syllabus_headers array, and from the item in place "selectedBeltID" (referencing the static variable set earlier).

    This way you can reuse all the same activities for showing data about the different belts and you only have one place to edit and update that data - in your resource files. The same thing goes for stuff like integer arrays and so on.

    And if you have some data that is only there in some special cases you can use the "selectedBeltID" as a check to see whether or not to show that data.

    Hope this was something of what you were looking for. If not, please specify!
    igorski88 likes this.
  3. igorski88

    igorski88 New Member

    I really Like your Idea and I will definitely use it.
    The issue I am having is placing the position id into the static variable and then using that id to choose which string array to use. Thank you in advance

Share This Page