Using the same activity for displaying different data (Android) - android

I am working on a simple quiz application for Android. It has 10 questions and displays them one by one. Each question has three options. When the user answers a question he's redirected to the next one.
I'm not sure what's the right way to implement this.
I guess I shouldn't make 10 different activities with the same look, just different text inside.
Probably I should reuse the same one, but how? And if I do, how'd I know which one is the 10th one in order to display the score after answering that one?

You can use a Listeners and an integer which contains the current question. You can use the switch from java to filter the value of the integer.

You may make array of questions and answers , then make a button to navigate to next index of question and loop up to the size of arrays.

Related

How to show exact amount of Views?

Let I have some number n. It can be equal to any integer number ranged between 2 and 15,for example. And according to this number, I need to show n TextView's(orButtons). I need this concept for creating kind of 4 pic 1 word quiz game. As you know, in this game , if secret word is banana,then app create 6 places for each letter. And my question is what kind of concepts to use in order to solve this problem? My idea for solution was following: creating some view and add to this view a TextView n times. But I don't think that it is right way to do that. Can you tell me what I have to use in order to achieve my goal?
Loads of ways to achieve this:
You couid just create the placeholders you want in an XML Layout, I would of thought EditText with maxLength=1 and then use .setVisibility to show the ones you need depending on question;
You could use a loop to generate the number of elements you want. See
here for code example

Is it possible in Android that each row from the query will create button?

We're making an app that can make surveys which is to be answered, of course.
But i'm not sure if it is possible that, for example, we will display all the list of inserted survey topics
and that in every topic, there'll be 1 button for each, generated individually ( sorry for the term. not really good in English. ) so that they can select it.
I'm also hoping to use it in the list of questions so that they can select from given answers using those buttons.
If it is possible, can you please give me some hints/starting lines how to make it?
Thanks in advance.
I think you need to overview ListView widget of Android first.
It helps to show lists you want.
And after you need to research Adapter you need. It is interface you must implement to use with ListView.

How do you save a (user-created) dynamic Layout in Android?

I have a button on my home screen that will add an edit text field every time it is pushed (I limited it to 20 for best practice). It is basically a small budgeting app. I want the user to fill in an X amount of dollars in one of the fields. Then, when they are ready, to come back to the app another time and that created EditText is still there filled with the value. I know how to utilize SharedPerfrences to hold the value. I do not, however, know how to hold that newly created EditText field when the user comes back.
I am acutally going to expand and have a button and a datepicker associated with each EditText field so soon click the button will create three objects, not just one. But I want to get one working first and will apply the principle to the others later. Any suggestions?
Sounds like a good candidate for a SQLite database.
For instance, I use a SQLite database to retain and recall the co-ordinates and types of widgets that the user has arranged within my application.
Note that you don't ever want to be trying to store and recall the actual EditText View object itself. In your database you need to devise your own table format that suits the kind of information you need to store. If you simply need to retain the states of a series of EditText fields then this could be as simple as having a table with just one column that contains a string value on each row. To build your UI up again from that database, you'd loop through and create a new instance of EditText, and set the text of each one from the table.
You would have to use Android Parcelable interface, refer to this to know as of how to implement it, refer to this question which I has asked on StackOverflow, it has a good answer.

How do I use hash-maps correctly when programming for Android?

I was told that I have to use a hash-map to store radio buttons. (The buttons as the key and their state as value) but I am new to Java and Android so It's kinda confusing.
I have a choice test with multiple questions and yes or no answers and I want to count the yes answers.
Maybe it's some simple thing to do but I can't figure out.
Any help would be appreciated.
Thanks
You could add a reference to all of your objects to a collection and iterate over them checking whether they are checked and counting them up.
Alternatively you could register an onClick listener on all of the buttons and increment/decrement a count when they are clicked.
There are multiple ways you could achieve this. I dont see why you need a hash map though, as the checked state is available on the button object itself. Your hash is useless.

Alphanumeric View in Android

I am developing an Android App which gives users an option 'Browse Alphanumerically'. Using this option let users view the list of items starting with a particular letter or number. Problem is that I cannot decide how to implement screen for this, which can work properly on any screen size. Please suggest me the best solution.
Thanks.
What I got from your question is that you want to show all alphabets and numbers to the user so they can jump directly to a entries start with the selected alphabet or number. If this is so, then one solution to your problem is use the Button or ImageButton any make a key pad of all alphabet and numbers. Don't forget to make them flexible enough for different screen sizes. Cheers.
Use a list activity. There are lots of tutorials on Google's developer site. When you want to narrow the list, just assign the smaller list to the ListView. Just filter your master list, sort it, and assign it to your list adapter.
Hope this was helpful.

Categories

Resources