How to handle a large number of activities in android studio - android

Iam a student and Iam developing an app for my college for downloading previous year question papers,my college has 14 departments and for each department 8 semesters and in each semester minimum 10 subjects are there so 14*2*8= 1120 java files and XML files I have to create if I keep on intenting from one activity to another it will take a huge time.how handle this huge activities.my app structure would be
Select department(14) >> Select sem(8)>> select subject(10)
Is there any methods like nestedif or something else to reduce the activity files.if there are any methods please do help me to complete the project.thanks in advance

No, you don't need that many activities. You need to write abstract activities that take parameters and displays different data based on those. At most I see 4 activities here- department selector, semester selector, subject selector, and the actual subject activity. And arguably some of those should be fragments instead, although that's more personal choice.

Related

How to make a android app to display questions paper from various stream?

I want to make an app which displays all previous year question papers.... now the problem is...My university has 8 streams to choose and each stream has 8 semesters and each semester has 5 subjects and I want to display papers for each subject when user click on subject name.
Example:-CSE
---Semester 2
---Subject name
----year
Now the problem is... for 8 stream I have to make 8 activities and each stream have 8 semester means again 8 activities for each stream and each semester has 5 subjects so I have to make again 40 activities for each stream and each activity hold various subjects.
So is there any simple way to display all the papers with minimum number of activities.
I am new in programming world so please suggest me simple solution for the question.
Your solution to the above stated problem is static. Try creating a dynamic app wherein you have only one activity for showing the paper. You can pass in the subject code and semester code to the activity when it is created. You can then use that information to fetch the papers that you want to display in that activity from the database or something.
What I mean to say is that, you can have one activity named main_activity wherein you make the user to select the branch and the semester and the subject. Then you can have a button which can be clicked to launch a new activity which shows the paper of the subject that the user selected.
When programming the show papers button, you can use intent to change the activity and can pass some variables to the activity that is going to be created. Something like this -
Intent intent = new Intent(MainActivity.this,ShowPapers.class);
intent.putExtra("Subject_code","CE501");
startActivity(intent);
For show papers activity you can use -
Intent intent = getIntent();
String subject_code=intent.getStringExtra("Subject_code");
Once you have the subject_code, you can fetch the papers for that subject code from the database.
Hope this helps! :)

How to customised ListView that have repeated structure in Android?

I'm new to android and I want to customize my application that have structures like following:
CompanyName-1:abc
employee-1:
employee-2:
CompanyName-2:pqr
employee-1:
CompanyName-3:xyz
employee-1:
employee-2:
employee-3:
employee-4:
In above structures, employee size may vary depending on data you have i.e. if your company have only 1 employee it should display only one employee, if 2 then 2 employees and etc.
I suggest you to make a good java structure with your data, for example a "company object" that contain an "ArrayList of employee". Afterwards, be interested with getView() method from your adapter.(Adapter for your listView).
Good Luck!

Make a Highscore Screen in App Inventor

I want to add a Highscore Screen to my Quiz App. I've already created a Highscore Screen with a start value, which contains the score the user has reached in the last round, the category-name and the difficulty.
I split this start value into 2 variables:
The first contains only the score and the other one the category and the difficulty. Now all in all I have 3 categories and 2 difficultys for each of them. Now I want to keep the top 10 Highscores of each category and difficulty. Like this:
Category 1 Difficulty 1
Category 1 Difficulty 2
Category 2 Difficulty 1
Category 2 Difficulty 2
Category 3 Difficulty 1
Category 3 Difficulty 2
As you can see, I will have 6 different Highscore lists.
Now my question:
How can I save all of the 6 lists in my TinyDB and reload the data again?
for each of the lists use its own tag for TinyDB
to save one of the lists, use the TinyDB.StoreValue block, to get it again in Screen.Initialize use the TinyDB.GetValue block, see also the docu and remember: on first run TinyDB is empty, see an example here how to handle that.
and: do the tutorials to get familiar with the basic concepts of App Inventor.

Android application structure issue

I'm working on application and I need some suggestions which is the best way to code it for Android. Basically it's something like event guide for a few cities. Imagine this :
I have an activity with 7 different buttons (7 different cities) and clicking on one of these buttons I'm opening a new activity where I have all months (January-December) as buttons again. If there is some event in February for example in the chosen city the button will be active and I will go to another activity where I have a list with the events. So my idea is to do it in this way :
Create one Activity with all Cities
Create one Calendar activity with all months.
When user select for example Paris, I'll send an extra via intent with an ID of the chosen city :
intent.putExtra("chosenCity", 2); //something like this
In the Calendar activity I will make active/inactive months buttons depending on that extra sent from Cities activity.
And when user chose a month I will send that chosenCity extra again to the ListViewEvents activity and populate the list view from Database (for example) depending on that extra.
So my question is : is it a good way to build an application like that? Or if it's not, which is the best way to achieve this?
Thanks in advance!
Sounds like you already know pretty much what you need to do. The only thing left is to implement it. The only thing I'll add is that your should probably store all your database and use a CursorAdapter to display them in the ListView. You can store all the events in the database and just create your select statement in such a way that it only selects the events you want to display at any given time. When using this CursorAdapter, I highly recommend you use the CursorLoader.

Android TextViews. Is parametrization possible? Is binding to model possible?

I am new to both Android and Stack Overflow. I have started developing and Android App and I am wondering two things:
1) Is it possible to parametrize a TextView? Lets say I want to render a text message which states something like: "The user age is 38". Lets suppose that the user age is the result of an algorithm. Using some typical i18n framework I would write in my i18n file something like "The user age is {0}". Then at run time I would populate parameters accordingly. I haven't been able to figure out how to do this or similar approach in Android.
2) Let's suppose I have a complex object with many fields. Eg: PersonModel which has id, name, age, country, favorite video game, whatever. If I want to render all this information into a single layout in one of my activities the only way I have found is getting all needed TextViews by id and then populate them one by one through code.
I was wondering if there is some mapping / binding mechanism in which I can execute something like: render(myPerson, myView) and that automatically through reflection each of the model properties get mapped into each of the TextViews.
If someone has ever worked with SpringMVC, Im looking for something similar to their mechanism to map domain objects / models to views (e.g. spring:forms).
Thanks a lot in advanced for your help. Hope this is useful for somebody else =)
bye!
In answer to #1: You want String.format(). It'll let you do something like:
int age = 38;
String ageMessage = "The user age is %d";
myTextView.setText(String.format(ageMessage, age));
The two you'll use the most are %d for numbers and %s for strings. It uses printf format if you know it, if you don't there's a quicky tutorial in the Formatter docs.
For #2 I think you're doing it the best way there is (grab view hooks and fill them in manually). If you come across anything else I'd love to see it.

Categories

Resources