Android Gridview appearing different in a real device

106 views Asked by At

I am currently working on an android application, but I am little confused with the gridview. I have managed to complete the whole code for gridview and I got it right when I run it on the emulator with Nexus 4 and Nexus 7. But when I am running it on a real device (htc 816 G) I am not getting the grid view as desired. Please check my code and help me.

This is what I am getting on emulator

http://share.shutterfly.com/action/welcome?sid=0AYsnDZq5ZMnLkA

This is what I am getting on real device

http://share.shutterfly.com/action/welcome?sid=0AYsnDZq5ZMnLiY

(I am new to Stack Overflow, so I can't upload any images, hence why I am giving links)

grid.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#EBF0FF">
 <GridView
    android:id="@+id/gridView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:numColumns="auto_fit"
    android:columnWidth="90dp"
    android:layout_marginTop="15dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"  
    android:horizontalSpacing="7dp"
    android:verticalSpacing="7dp"
    android:gravity="center"
    android:stretchMode="columnWidth" >
</GridView>
</LinearLayout>

grid_element.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="80dp"
    android:layout_height="80dp" >

<TextView
    android:id="@+id/text"
    android:background="@drawable/grid_elemt_style"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:textSize="18sp"
    android:gravity="center" />
</LinearLayout>

grid_element_style.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:bottom="1dp"
    android:left="1dp"
    android:right="1dp"
    android:top="1dp">
    <shape android:shape="ring">
        <solid android:color="#4E78F5" />
    </shape>
  </item>
 </layer-list>

gridview.java

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;

public class gridview extends Activity {
    GridView grid;
    Intent mIntent = getIntent();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.grid);
        grid = (GridView)findViewById(R.id.gridView);
        final int Value = getIntent().getExtras().getInt("val");
        final int pos = getIntent().getExtras().getInt("MY_pos");

        List<Integer> intList = new ArrayList<Integer>();
        switch(Value) {
            case 1:
                for (int i = 1; i <= (informations.stopb[pos] - informations.startb[pos] + 1); i++) {
                    intList.add(i);
                }
                break;
            case 2:
                for (int i = 1; i <= (informations.stopm[pos] - informations.startm[pos] + 1); i++) {
                    intList.add(i);
                }
                break;
            case 3:
                for (int i = 1; i <= (informations.stopc[pos] - informations.startc[pos] + 1); i++) {
                    intList.add(i);
                }
                break;
            case 4:
                for (int i = 1; i <= (informations.stopp[pos] - informations.startp[pos] + 1); i++) {
                    intList.add(i);
                }
                break;
            default:
                break;
        }

        ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this,R.layout.grid_element, R.id.text, intList);
        grid.setAdapter(adapter);
    }
}
0

There are 0 answers