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


Last Updated:

  1. sambocrockett

    sambocrockett Member This Topic's Starter

    Joined:
    Jun 8, 2010
    Messages:
    22
    Likes Received:
    1
    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.
     

    Advertisement
  2. sambocrockett

    sambocrockett Member This Topic's Starter

    Joined:
    Jun 8, 2010
    Messages:
    22
    Likes Received:
    1
    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.
     
  3. sambocrockett

    sambocrockett Member This Topic's Starter

    Joined:
    Jun 8, 2010
    Messages:
    22
    Likes Received:
    1
    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.
     
  4. id0001

    id0001 Well-Known Member

    Joined:
    Apr 20, 2010
    Messages:
    142
    Likes Received:
    23
    It is not that you ask stupid questions, but... have you read the developers guide?
    It explains the basics of android activities, views, widgets and much more.
    All your current questions are explained in the guide.

    The Developer's Guide | Android Developers
     
  5. cp1

    cp1 Well-Known Member

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35
    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);
     
  6. sambocrockett

    sambocrockett Member This Topic's Starter

    Joined:
    Jun 8, 2010
    Messages:
    22
    Likes Received:
    1
    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.
     
  7. cp1

    cp1 Well-Known Member

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35
    Can you post your code?
     
  8. sambocrockett

    sambocrockett Member This Topic's Starter

    Joined:
    Jun 8, 2010
    Messages:
    22
    Likes Received:
    1
    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.
     
  9. id0001

    id0001 Well-Known Member

    Joined:
    Apr 20, 2010
    Messages:
    142
    Likes Received:
    23
    have you thought about using an ImageView?
     
  10. sambocrockett

    sambocrockett Member This Topic's Starter

    Joined:
    Jun 8, 2010
    Messages:
    22
    Likes Received:
    1
    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.
     
  11. cp1

    cp1 Well-Known Member

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35
    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) ;
    }


    }



    });


    }
    }
     
  12. sambocrockett

    sambocrockett Member This Topic's Starter

    Joined:
    Jun 8, 2010
    Messages:
    22
    Likes Received:
    1
    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
    [​IMG]
     
  13. sambocrockett

    sambocrockett Member This Topic's Starter

    Joined:
    Jun 8, 2010
    Messages:
    22
    Likes Received:
    1
    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
     
  14. cp1

    cp1 Well-Known Member

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35
    I was reading up more on android and found this article. It goes through an example of what not to do for an image -- hope this helps you with your project, if only to tell you what not to do.

    Avoiding Memory Leaks | Android Developers
     

Share This Page

Loading...