3

i have a simple app that displays a table and below that displays an imageview with an image that changes depending on the row clicked on the table. It works and displays fine on the emulator but when i install it on my test phone it does not show. my code is here:

package com.coreservlets.widgets;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TableRow;
import com.welly.keychords.R;

public class keya extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.keya);
    }

    public void rowClick(View view) {
        ImageView imagev = (ImageView) findViewById(R.id.imageView1);
        switch(view.getId()) {
        case R.id.one:
           imagev.setImageResource(R.drawable.achord);
            break;
        case R.id.two:
            imagev.setImageResource(R.drawable.bminor);
             break;
        case R.id.three:
            imagev.setImageResource(R.drawable.csharpdbminor);
             break;
        case R.id.four:
            imagev.setImageResource(R.drawable.dchord);
             break;
        case R.id.five:
            imagev.setImageResource(R.drawable.echord);
             break;
        case R.id.six:
            imagev.setImageResource(R.drawable.fsharpgbminor);
             break;
        case R.id.seven:
            imagev.setImageResource(R.drawable.gsharpdim);
             break;
        }
    }
}

my xml code is here:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FF909090"
    android:stretchColumns="1" >

    <TableRow
    android:id="@+id/one"
    android:onClick="rowClick">

        <TextView
            android:layout_margin="2dip"
            android:layout_marginRight="2dip"
            android:background="#0000ff"
            android:padding="3dip"
            android:text="I" />

        <TextView
            android:layout_margin="2dip"
            android:layout_marginLeft="1dip"
            android:background="#0000ff"
            android:gravity="center"
            android:padding="3dip"
            android:text="A"
           />
    </TableRow>

    <TableRow
        android:id="@+id/two"
    android:onClick="rowClick">

        <TextView
            android:layout_column="0"
            android:layout_margin="2dip"
            android:background="#0000ff"
            android:padding="3dip"
            android:text="II" />

        <TextView
            android:layout_margin="2dip"
            android:background="#0000ff"
            android:gravity="center"
            android:padding="3dip"
            android:text="Bm" />
    </TableRow>

    <TableRow
        android:id="@+id/three"
    android:onClick="rowClick">

        <TextView
            android:layout_column="0"
            android:layout_margin="2dip"
            android:background="#0000ff"
            android:padding="3dip"
            android:text="III" />

        <TextView
            android:layout_margin="2dip"
            android:background="#0000ff"
            android:gravity="center"
            android:padding="3dip"
            android:text="C#m" />
    </TableRow>

    <View
        android:layout_height="2dip"
        android:background="#FF909090" />

    <TableRow android:background="#0000ff" >
    </TableRow>

    <TableRow
        android:id="@+id/four"
    android:onClick="rowClick">

        <TextView
            android:layout_margin="2dip"
            android:background="#0000ff"
            android:padding="3dip"
            android:text="IV" />

        <TextView
            android:layout_margin="2dip"
            android:background="#0000ff"
            android:gravity="center"
            android:padding="3dip"
            android:text="D" />
    </TableRow>

    <View
        android:layout_height="2dip"
        android:background="#FF909090" />

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </TableRow>

    <TableRow
        android:id="@+id/five"
    android:onClick="rowClick">

        <TextView
            android:layout_margin="2dip"
            android:layout_marginRight="2dip"
            android:background="#0000ff"
            android:padding="3dip"
            android:text="V" />

        <TextView
            android:layout_margin="2dip"
            android:layout_marginLeft="1dip"
            android:background="#0000ff"
            android:gravity="center"
            android:padding="3dip"
            android:text="E" />
    </TableRow>

    <TableRow
        android:id="@+id/six"
    android:onClick="rowClick">

        <TextView
            android:layout_margin="2dip"
            android:layout_marginRight="2dip"
            android:background="#0000ff"
            android:padding="3dip"
            android:text="VI" />

        <TextView
            android:layout_margin="2dip"
            android:layout_marginLeft="1dip"
            android:background="#0000ff"
            android:gravity="center"
            android:padding="3dip"
            android:text="F#m" />
    </TableRow>

    <TableRow
        android:id="@+id/seven"
    android:onClick="rowClick">

        <TextView
            android:layout_margin="2dip"
            android:layout_marginRight="2dip"
            android:background="#0000ff"
            android:padding="3dip"
            android:text="VII" />

        <TextView
            android:layout_margin="2dip"
            android:layout_marginLeft="1dip"
            android:background="#0000ff"
            android:gravity="center"
            android:padding="3dip"
            android:text="G#dim" />
    </TableRow>





    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="114dp"
        android:background="#000000"
        android:maxLines="10"
        android:text="The relative minor of the Major key of A is F#m. The 12 bar blues progression in A is: \n A | A | A | A | D | D | A | A | E | D | A | E" />





    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#ffffff" />

</TableLayout>

the code for the imageview is right at the bottom of the xml layout. Any help on how to debug this?

3
  • i changed the background of the imageview to white to try and see if the view was appearing on phone but the image was not loading, still nothing. no white box where the imageview should have been Nov 2, 2012 at 7:25
  • try reducing height of your textview above that imageview Nov 2, 2012 at 7:30
  • @user1505181 Can you provide some more settings of both your device and emulator (density, resolution)? And for testing purposes, try to set the layout_width to some static value (IE 128dp). Also, are your drawables in /res/drawable or does it have any qualifier (drawable-hdpi for example)? What happens when you put the imageview in a separate layout (ie as root a linearlayout with as children, the tablelayout and a relativelayout with the textview and imageview)? Is the click registered (probably it is, but still worth checking)? Nov 2, 2012 at 8:04

5 Answers 5

1

This is just a guess, given that there can be other things that can go wrong - do you have drawables in the correct resource folder? Maybe you have images in the drawable-mdpi or drawable-ldpi folder that corresponds to the emulator and not in the drawable-hdpi corresponding to the device.

To test, suggest you to create a drawable folder (without any qualifier) and copy all the drawable files to that folder and check if you see the ImageView.

Update:

Use the hierarchyviewer to check the properties of the UI elements.

4
  • all files are in drawable only. i dont think the problem is with the resources though, as i said i have set the background of the imageview as white so it should appear on the screen even without a picture loaded into it Nov 2, 2012 at 7:42
  • The background color will be visible only if the ImageView has a size. Without a drawable image, the size of the ImageView is 0 and hence no color will be seen.
    – Rajesh
    Nov 2, 2012 at 7:44
  • hmm ok thank you for that information. the dimensions of the images are 217 x 217, could that be something to do with it? Nov 2, 2012 at 7:47
  • Please check the update on debugging UI elements using hierarchyviewer
    – Rajesh
    Nov 2, 2012 at 7:49
1

ive solved it by changing the images to png format and making them 50% smaller. not sure why that works but it does!

0

contain all the views in the xml (except the layout itself) in a scrollview. Maybe your phone screen height is not too large.

1
  • i am testing on a samsung galaxy s2, which has bigger screensize than the emulator i am running Nov 2, 2012 at 7:45
0

Is the image view simply not showing? does it seem to be cutoff? try setting android:weight="1.0" or whatever number you want to the imageview or put the whole thing in a scroll view. that will solve the problem if it is being cutoff.

also another suggestion...

try wrapping the whole table layout inside a linear layout, and pull out your text view and image view at the very end. I am not 100% sure but I think you're only supposed to have table row inside of a table layout... however since its working on the emulator, not too sure.

-edit-

try this (put your textview and imageview in a tablerow)... it might work.

<TableRow>
 <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="114dp"
        android:background="#000000"
        android:maxLines="10"
        android:text="The relative minor of the Major key of A is F#m. The 12 bar blues progression in A is: \n A | A | A | A | D | D | A | A | E | D | A | E" />
</TableRow>

<TableRow>
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#ffffff" />
</TableRow>
4
0

Perhaps a bit old, but this thread still helped me. I had the same problem. On the emulator my image, JPG, was showing perfectly. But on my phone the image was not displayed.

When I put a background color on my ImageView I did see the color on my phone, but no image.

Then I scaled down the image, from around 2000px width to 1000px width. And voila.. the image was visible.

It seems there are maximum image resoluations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.