• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Need a push in the right direction :) storing pictures within an app?

Hello,

Im trying to develop my first app and I want to create a simple one that uses a group of pictures that I have and allows the user to browse through them using buttons. Getting the buttons on the screen wasnt to hard but thats about it for my knowledge so far as I am just a rookie using the android sdk. Im thinking that I can store the pics in the resource file and make some kind of call to draw them to screen when the user pushes the button.

So what I need to know if possible is......

How to I store pictures inside an app.....is that even possible? I would imagine it has to be since there are sound board apps and those sounds had to be stored in the app.....Im guessing.

How do I draw those pictures to the screen.

And finally how can I use a button to browse through the pictures.
 
Ok so Ive figured out how to put the image files into the app.....that was easy enough. Now Im still stuck on how to call them to screen by the use of buttons.

Should I store all the image files to be used in the app into some kind of array and then the buttons to go back and forth.......does any one know how I would go about doing that.
 
Upvote 0
Ok.....i suppose that most people messing with android are either like myself and have almost no experience or are so advanced that they find my thread to elementary to comment on.....

Anyway,

So now I have the picture drawn to the screen but I dont know how to make the buttons switch the pictures back and forth

I know I need to make an array, assign each picture a value in the array, and then set up some kind of loop or something that tells the app that if a button is pressed go to the next pic and draw it to the screen.....or......go back to the previous one and draw it to the screen.
 
Upvote 0
I'm sure there's some imagelistadapter type class that would work easily, but I'm very new to android programming. If there's only a few pictures you can brute force it:

int i = 0;
long pictures[] = {R.id.picture1, R.id.picture2, R.id.picture3, R.id.picture4};
(I think these are longs?)

next button pressed:
i++;
displayImage(pictures);

previous button pressed:
i--;
displayImage(pictures);
 
Upvote 0
I have read the developers guide but I cant seem to put any of it together to make stuff work. Also half of the time I tried some of their tutorials I have errors all the way through my code and none of the fixes that come up make anything work. Im a really low low level programmer and Ive been trying to learn a bunch of things at once but I just cant seem to figure out how to get things to work together.
 
Upvote 0
So far Ive just been getting by using some stuff I found from tutorials and other places so heres what I have in my projects java file in the src group of files


package test.button;

import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class button extends Activity {
/** Called when the activity is first created. */

Button myButton;
EditText myText;
protected int count;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().setBackgroundDrawableResource(R.drawable.hot_girls) ;

myButton = (Button) findViewById (R.id.my_button);
myText = (EditText) findViewById (R.id.my_text);

myText.setSingleLine();
myText.setInputType(InputType.TYPE_NULL);

myButton.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
myText.setText("youve touched the screen"+ ++count +" times");

}



});


}
}


I know its not pretty and its not much but Im kinda stuck and everything else Ive used just produces errors. So far the only thing Ive been able to do is use getwindow() to set a pic as the background.
 
Upvote 0
I just looked at that ImageView class but I have no idea how I would implement it to work with what I have. How would I go about using an ImageView?

Im trying to get the buttons I have set up go to the next or previous picture in the list of pictures that Ill have in the res folder. Thats pretty much it. I can see that the more I look into doing this the more Im lost.
 
Upvote 0
Does this work? (I didn't test it) -- change the R.drawable to whatever your labels are.

package test.button;

import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class button extends Activity {
/** Called when the activity is first created. */

Button myButton;
EditText myText;
protected int count;
int i = 0;
long pictures[] = {R.drawable.hot_girls1, R.drawable.hot_girls2, R.drawable.hot_girls3, R.drawable.hot_girls4};
int numGirls = 4;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().setBackgroundDrawableResource(R.drawable.hot_girls1) ;

myButton = (Button) findViewById (R.id.my_button);
myText = (EditText) findViewById (R.id.my_text);

myText.setSingleLine();
myText.setInputType(InputType.TYPE_NULL);

myButton.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
myText.setText("youve touched the screen"+ ++count +" times");
if (i < (numGirls - 1))
{
i++;
getWindow().setBackgroundDrawableResource(pictures) ;
}
else

{
i = 0;
getWindow().setBackgroundDrawableResource(pictures) ;
}


}



});


}
}
 
Upvote 0
Im still getting an error related to the long that holds the array with my resources. Im getting the error in these lines


public void onClick(View arg0) {
myText.setText("youve touched the screen"+ ++count +" times");
if (i < (numGirls - 1))
{
i++;
getWindow().setBackgroundDrawableResource(pictures) ;
}
else

{
i = 0;
getWindow().setBackgroundDrawableResource(pictures) ;
}



The setBackgoundDrawableResource is getting an error in both instances.....I tried the fixes but they dont work either and it says its because the long doesnt work with the data type or something
moz-screenshot.png
 
Upvote 0
Okay I got it to actually work :)

I messed with some of the quick fixes and changed the setBackgroundDrawableResource(pictures[1])

to this


@Override
public void onClick(View arg0) {
myText.setText("youve touched the screen"+ ++count +" times");
if (i < (numGirls - 1))
{
i++;
getWindow().setBackgroundDrawableResource((int) pictures) ;
}
else

{
i = 0;
getWindow().setBackgroundDrawableResource((int) pictures) ;
}

So all that was needed was declaring that the pics were of int type......I think....can some one please tell me if thats whats going on there because I really dont have enough experience to be sure LOL
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones