Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7630543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:07:54+00:00 2026-05-31T06:07:54+00:00

In my app i have a button that when click loads a new image

  • 0

In my app i have a button that when click loads a new image into an image view. The problem is that while it does this the text on the button changes orientation.

Heres my code for this class

package com.michaelpeerman.demotivational_posters;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class ImageGallery extends Activity {
public ImageView i;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
setContentView(R.layout.image_gallery);
Button next = (Button) findViewById(R.id.next);
Button download = (Button) findViewById(R.id.download);
download.setOnClickListener(this.buttonhandler);
next.setOnClickListener(this.buttonhandler);
    try {
        int rand = 1 + new Random().nextInt(2368);
        String url = "http://someurl.com/"+rand+".jpg";
          i = (ImageView)findViewById(R.id.imageView);
          Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(url).getContent());
          i.setImageBitmap(bitmap); 
        } catch (MalformedURLException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
}

View.OnClickListener buttonhandler = new View.OnClickListener()
{
  public void onClick(View v)
  {

    switch (v.getId())
    {
    case R.id.next:
        loadImage();
        break;

    }
  }
};

void loadImage(){


        int rand = 1 + new Random().nextInt(2368);
        String url = "http://someurl.com/"+rand+".jpg";     
    try {

          Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(url).getContent());
          i.setImageBitmap(bitmap); 
        } catch (MalformedURLException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
}
}

The text is fine when the app first loads with the first button. But the text on the buttons change when i click next.

Here is the layout as well

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout 
    android:id="@+id/tablelayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    <TableRow android:id="@+id/tableRow1"
            android:layout_height="wrap_content">
        <Button android:id="@+id/download"
                android:layout_width="1dip"
                android:layout_height="fill_parent"
                android:layout_weight=".45"
                android:text="Download"/>
        <Button android:id="@+id/next"
                android:layout_width="1dip"
                android:layout_height="fill_parent"
                android:layout_weight=".45"
                android:text="Next"/>

    </TableRow>



</TableLayout>
<TableRow android:id="@+id/tableRow2"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_below="@id/tablelayout1">
                        <ImageView android:id="@+id/imageView" android:layout_width="fill_parent"
    android:layout_height="wrap_content"  />

    </TableRow>


</RelativeLayout>

Here are pictures of the issue

When app first loads

After clicking Next

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:07:55+00:00Added an answer on May 31, 2026 at 6:07 am

    Try this with your modification.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent" 
                android:layout_height="wrap_content"  >
                <Button
                    android:id="@+id/dwnld"
                    android:text="Download" 
                    android:layout_margin="2dp"
                    android:textColor="#000000"
                    android:layout_weight="0.5"
                    android:layout_width="0dp" 
                    android:layout_height="30dp"/>
               <Button
                    android:id="@+id/next"
                    android:text="Next"
                    android:layout_margin="2dp" 
                    android:textColor="#000000"
                    android:layout_weight="0.5"
                    android:layout_width="0dp" 
                    android:layout_height="30dp"/>
            </LinearLayout>
            <ImageView android:id="@+id/imageView" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"  />
    
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello StackOverflow'ers, I have a (flex) app that, on the click of a button,
I have a .NET application that contains a checkbox (System.Windows.Forms.Checkbox). This component (WindowsForms10.BUTTON.app.0.378734a1) is
I have a button that launches the google maps app on my device via
I'm now testing GKPeerPickerController. I have a simple app that just have a button
My Basic Goal A Rails app that can load new content via Ajax while
I have a simple Wall.cshtml view that loads a _Search.cshtml Partial View that looks
so i have this app that is a training program in this app the
I have a native iPhone app that just loads a website using UIWebView .
in my android app, I have a button that leads to an activity which
I have several buttons on my app that are being created dynamically. They are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.