Maybe I don't completely understand logcat. as of now it's been useful
to see what line is causing my app to crash. But in this case it's not
crashing and I dont see anything out of the ordinary in my logcat.
Anyone able to see what I'm doing wrong?

On Jun 21, 3:59 pm, BryBam <[email protected]> wrote:
> Well I appreciate the thought on another way I could go about doing
> this. However I have a very similar approach on another activity  with
> text and it works great.  I probably will want to look into your
> suggestion later on. But for now im simply looking to see what i'm
> doing wrong with my current code. At least for now, so i can get some
> peace of mind. Looking at it I see nothing wrong. Neither does
> eclipse.
>
> Lets just forget about the button, say i literally did just want a
> different image to come up whenever the page was visited. Anyone see
> the error? This has been bugging me for days.
>
> On Jun 21, 3:09 am, jamesc <[email protected]> wrote:
>
> > I've only scanned your code and note that you're using an Intent on
> > the same class to essentially get the 'redraw/reload of a random
> > image' to occur.  I'm not sure that this would be the best way of
> > going about what you want to achieve.  (As an aside try using logcat
> > to see what's happening; is all OK with your AndroidManifest.xml, as
> > there may be an issue with the resolution of the Intent?).
>
> > Perhaps you should just look at finding (findViewById()) the ImageView
> > and assigning it to a member field (you're currently finding it and
> > assigning it on the stack), then in your onClick() override just do
> > mMyImageView.setImageDrawable() (or whatever) to re-set what the
> > rendered image should be?
>
> > On Jun 20, 11:00 pm,BryBam<[email protected]> wrote:
>
> > > I would also like to point out that I've tried all three of these
>
> > > private Integer [] mImageIds = {
> > >             R.drawable.icon,
> > >             R.drawable.shoticon,
> > >             R.drawable.mixicon,
> > >             };
>
> > > private static final Integer [] mImageIds = {
> > >             R.drawable.icon,
> > >             R.drawable.shoticon,
> > >             R.drawable.mixicon,
> > >             };
> > > private static Integer [] mImageIds = {
> > >             R.drawable.icon,
> > >             R.drawable.shoticon,
> > >             R.drawable.mixicon,
> > >             };
>
> > > NONE OF THOSE HAVE MADE A DIFFERENCE.
>
> > > On Jun 20, 5:48 pm,BryBam<[email protected]> wrote:
>
> > > > I've been staring at this for hours. It compiles fine with no errors
> > > > and loads the activity on my nexus. The button and the menu items load
> > > > fine with no issues at all. It's simply not loading any of the
> > > > drawables i'm specifying :/ any ideas what I did wrong?
>
> > > > All I want is whenever this activity is brought up it randomly chooses
> > > > an image from the drawables i specify.
>
> > > > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> > > > HERE'S MY CODE FOR THE JAVA
> > > > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> > > > package com.package.name;
>
> > > > import java.util.Random;
> > > > import android.app.Activity;
> > > > import android.content.Intent;
> > > > import android.os.Bundle;
> > > > import android.view.View;
> > > > import android.widget.ImageView;
> > > > import android.view.Menu;
> > > > import android.view.MenuInflater;
> > > > import android.view.MenuItem;
> > > > import android.view.View.OnClickListener;
>
> > > > public class RandomImage extends Activity implements OnClickListener{
>
> > > >     private static final Random rgenerator = new Random();
>
> > > >     Integer [] mImageIds = {
> > > >             R.drawable.icon,
> > > >             R.drawable.shoticon,
> > > >             R.drawable.mixicon,
> > > >             };
>
> > > > @Override
> > > > public void onCreate(Bundle savedInstanceState) {
> > > >     super.onCreate(savedInstanceState);
> > > >     setContentView(R.layout.randomimage);
>
> > > >     Integer q = mImageIds[rgenerator.nextInt(mImageIds.length)];
>
> > > >     ImageView iv = (ImageView) findViewById(R.id.imageviewyeah);
> > > >     iv.setTag(q);
>
> > > >     View nextButton = findViewById(R.id.next_image_button);
> > > >     nextButton.setOnClickListener(this);
>
> > > > }
>
> > > >     @Override
> > > >     public void onClick(View v) {
> > > >     switch (v.getId()) {
> > > >     case R.id.next_image_button:
> > > >         Intent i = new Intent(this, RandomImage.class);
> > > >         startActivity(i);
> > > >         break;
> > > >     }
>
> > > > }
>
> > > >     @Override
> > > >         public boolean onCreateOptionsMenu (Menu menu) {
> > > >                 super.onCreateOptionsMenu(menu);
> > > >                 MenuInflater inflater = getMenuInflater();
> > > >                 inflater.inflate(R.menu.menu3, menu);
> > > >                 return true;
> > > >         }
>
> > > > @Override
> > > > public boolean onOptionsItemSelected (MenuItem item) {
> > > >                 switch (item.getItemId()) {
> > > >                 case R.id.menu:
> > > >                         startActivity(new Intent(this, Main.class));
> > > >                         return true;
>
> > > > }
>
> > > > return false;
> > > >         }
>
> > > > }
>
> > > > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> > > > AND HERES MY CODE FOR THE LAYOUT.XML
>
> > > > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <LinearLayout
> > > >     android:orientation="vertical"
> > > > xmlns:android="http://schemas.android.com/apk/res/android";
> > > > android:id="@+id/widget0"
> > > > android:background="@drawable/nhiebg"
> > > > android:layout_width="fill_parent"
> > > > android:layout_height="fill_parent"
> > > >     android:layout_gravity="center" >
>
> > > > <ImageView
> > > >         android:id="@+id/imageviewyeah"
> > > >         android:tag="q"
> > > >         android:layout_width="wrap_content"
> > > >         android:layout_height="wrap_content"
> > > >         android:layout_gravity="center">
> > > > </ImageView>
>
> > > > <Button
> > > >         android:id="@+id/next_image_button"
> > > >         android:text="Next Image"
> > > >         android:layout_width="fill_parent"
> > > >         android:layout_height="wrap_content"
> > > >         android:padding="10dip"
> > > >         android:typeface="serif"/>
>
> > > > </LinearLayout>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to