Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Button text changes to vertical after clicking button
    primarykey
    data
    text
    <p>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.</p> <p>Heres my code for this class</p> <pre><code>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(); } } } </code></pre> <p>The text is fine when the app first loads with the first button. But the text on the buttons change when i click next.</p> <p>Here is the layout as well</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TableLayout android:id="@+id/tablelayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"&gt; &lt;TableRow android:id="@+id/tableRow1" android:layout_height="wrap_content"&gt; &lt;Button android:id="@+id/download" android:layout_width="1dip" android:layout_height="fill_parent" android:layout_weight=".45" android:text="Download"/&gt; &lt;Button android:id="@+id/next" android:layout_width="1dip" android:layout_height="fill_parent" android:layout_weight=".45" android:text="Next"/&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; &lt;TableRow android:id="@+id/tableRow2" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_below="@id/tablelayout1"&gt; &lt;ImageView android:id="@+id/imageView" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;/TableRow&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Here are pictures of the issue</p> <p><img src="https://i.stack.imgur.com/SUtGp.png" alt="When app first loads"></p> <p><img src="https://i.stack.imgur.com/UykA6.png" alt="After clicking Next"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload