Image Handling in android - java

I'm new to android and I'm stuck. I want to create an app (Picture Quiz) in which an image shown up with specific name under it in a textview. User will choose one answer and new image and its name comes, and they continously keep on coming until the user chooses the wrong answer. Then it will start again but this time images and their names should be shuffled.
I don't know where to put all these images (150 of them) either in drawables or somewhere else. How can i get and show both image and name using one ID and how can i shuffle them. Will i needed sqlite database?
Note: Sorry for lack of data and presentation. I didn't started it yet because i did not found any solutions yet.

one of the best way is
1.
store all images in drawable
2.
Make POJO file which contains all three id, path (R.drawable.image1), name
3.
use Arraylist to insert all data
4.
use Random to shuffle
sure, it's working, will get back further for more.

Related

Random Image generator app does not want to work on android studio 3.1.4

So for a small assignment, I was tasked with making a program that will generate a random image from a file on the computer
what I did was move the icons from the desktop to the drawable folder
in the image you can see that the files are there under the drawable folder
Here is the user interface
the code is also available in the picture. The issue is that the program would crash after I press the button and no picture is ever shown.
It looks perfect to me and at this point, I do not know what is wrong with it
Thank you for whoever answers this
Ps. I am using a mac for this (not sure how important this piece of info is )
image.setImageResource(i) you are passing random number in the setImageResources
You are passing wrong Image Resource Id
so replace with the image.setImageResource(array[i]) because your image resources ids stored in this array
Simply replace image.setImageResource(i) by image.setImageResource(array[i]).
What you want is to access the resource id which is stored in the array.

How to create a scoreboard in android studio?

I have a game where I want to display a scoreboard with the previous highscores. I also want to see these scores even if I re-open the app. Is it possible to display it in a TextView? Also, how am I supposed to save the scores locally?
how am I supposed to save the scores locally?
You would use a database. There are a number of libraries to simplify it, I recommend SugarORM.
Is it possible to display it in a TextView
No. You'll almost always want something more than a single TextView. That said, what to use depends a lot on the layout you want to have.

Android - How to show list data without scrolling

This is my application require :
- Get data from a server (JSON)
- Show all data report like image above. Data will display as multi page ( do not scroll), use next and previous button to switch
See how I want:
I can get data from server and show data as listview. But I have some problem and need help.
1. How to display data like image I attached. I found some way but seem it is not good
2. How to display data as multi page. I do not know exactly how much data because it depend data on Server, i have to show all data on server. Pages should auto generate depend on data.
Thanks you.
Simplest way to do it would be to create three datasets (let's say arraylists) and keep previous page data in one and current and future in the next one.
Then put an onClickListener that changes the data in listviews and then notify adapter using .notifyDatasetChanged().
This is not an default Android Behavior, So Please do not follow this design. Better to use Load More Functionality :)
You can refer links for that.
ListView to load more items when reached to an end
LoadMore library
Infinite Scroll ListView

Loop through SqlLite records. How is that efficient, in my case?

I have one question.
I have an application which retreives images from my web server. My activity shows one image and two buttons (previous and next).
I want to upgrade my app, and integrate "favourites" option. So if user likes particular image, url string (not image) is saved in sqlite database.
Question:
I will put ImageView and act like a button. That ImageView will show a hearth or something so it will indicate that user can tap, to save url to sqlite database. I want that ImageView be different if that url string already exists in database. That means that with every image I will need to loop through all urls in database. How is that efficient? Can I do that, or I will afect device performance?
So again if somebody didn't understood.
Show activity where image is shown
Click on button (next , previous )
Check through all urls (or until match is detected) in database in case it matches
If there is a match, change ImageView ( like, from yellow star, to red star. That means , image is already "favourited")
Will this affect android performance? (
I hope you understand what I meant.
Thank you for help.
I think your question is regarding the performance of SQLite SELECT statements.
You say "Check through all urls (or until match is detected) in database in case it matches".
I think you're implying a loop, but really you just want to build your SELECT statement properly so SQL does the heavy lifting. Selecting a single row from the DB shouldn't be slow. Selecting ALL the rows, then looping in java might be.
You want to do something like:
SELECT * FROM `table` WHERE `url`="http://www.someurl.com/image.jpg"
Which would return one result that's an exact match. no loops, just if you have a result, the image is saved, and if nothing is returned, the image is not saved.
Unless you have millions of entries, I imagine the above technique will perform quite well.
Use SharedPreferences for this purpose it is much better for performance here Vogella has some good tutorial for this , and android provide one too , it is much easier to detect duplicates too

How do I save some textviews and load them from another class?

In my app, i have you put in some information through some edit text. Then you hit this button and it starts another activity that does some calculations and then displays results through text views. Well i want to be able to save all of those text views, and then open them up later. On the home screen i have a load button. When you click it, I want to be able to see the stuff I've saved and be able to open it by clicking on it. I'm new to android, so I'm having a hard time figuring this out. How should I go about doing this?
Use SharedPreferences...Check out..
http://www.vogella.com/articles/AndroidFileBasedPersistence/article.html
http://androiddeveloperspot.blogspot.in/2013/01/sharedpreference-in-android.html
this will help.
I see two questions in your question. The first is how to pass data from one Android activity to another.
The best way to do that is by using the putExtra method of the Intent class and then the getExtras method to extract the data in the receiving activity. Please see this SO quest and answers for more details.
For your second question, how to save data that can be recalled at a later by the main activity, you can use the SharedPreferences APIs. See this web page for more information on that. Basically the shared preferences APIs allow you to save key-value pairs of information which in your case can be field names (keys) and their associated values. For this you would want private preferences and pick a unique name for this preference file.

Categories

Resources