Note that there are some explanatory texts on larger screens.

plurals
  1. POGridView Behaves Differently on phone and Emulator
    primarykey
    data
    text
    <p>I've been creating an app, which has its first activity as a gridView having 6 items , I've created a custom adapter and each item in the Grid contains an image and a <code>textView</code> under it . The problem is this app runs in emulator but when I tried it on phone the image icons I added gets misplaced (sorry, I don't have image of that).</p> <p>Here is the image from emulator,</p> <p><img src="https://i.stack.imgur.com/1xk2j.jpg" alt="enter image description here"></p> <p>when I run it on phone the pig.png comes first position mouse.png in 2nd, rest of the icons are also misplaced ... It behaves annoyingly because <strong>Sample Video option is for streaming sample videos from youtube , after playing a video the menu items reset to the right place(like the above jpeg)</strong>.I dont know what I did wrong . here is my codes</p> <p>main.xml</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Learnixmba" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="MBA Online Video " android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/CaptionText" android:textStyle="bold" /&gt; &lt;TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="@string/tution_class" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/CaptionText" android:textStyle="bold" /&gt; &lt;TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="@string/www_learnixmba_com" android:textAppearance="?android:attr/textAppearanceLarge" android:textSize="20sp" /&gt; &lt;GridView android:id="@+id/gridMain" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="bottom" android:layout_marginTop="10dp" android:fadingEdge="vertical|horizontal" android:fastScrollEnabled="true" android:numColumns="3" &gt; &lt;/GridView&gt; </code></pre> <p></p> <p>this is the row.xml(for Gridview)</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/GridItem" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#ffffff" android:gravity="center_horizontal" android:orientation="vertical" &gt; &lt;ImageView android:id="@+id/grid_item_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /&gt; &lt;TextView android:id="@+id/grid_item_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="@string/textview" android:textColor="@color/CaptionText" /&gt; </code></pre> <p></p> <p>and The main java File</p> <pre><code>package info.learnixmba; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; import android.widget.GridView; public class Learnixmba extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_learnixmba); Common.setBackGround(this); GridView mainGrid = (GridView)findViewById(R.id.gridMain); mainGrid.setAdapter(new ImageAdapter(this)); // setting onItemClickListner mainGrid.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // TODO Auto-generated method stub Intent go = new Intent(); switch(position){ case 0: go = new Intent(getBaseContext(),Universities.class); break; case 1: go = new Intent(getBaseContext(),AboutUs.class); break; case 2: go = new Intent(getBaseContext(),Faq.class); break; case 3: go = new Intent(getBaseContext(),SampleVideos.class); break; case 4: go = new Intent(getBaseContext(),HowToEnroll.class); break; case 5: go = new Intent(getBaseContext(),Benefits.class); break; }startActivity(go); } }); } public class ImageAdapter extends BaseAdapter { Context MyContext; public ImageAdapter(Context _MyContext) { MyContext = _MyContext; } @Override public int getCount() { /* Set the number of element we want on the grid */ return 6; } @Override public View getView(int position, View convertView, ViewGroup parent) { View MyView = convertView; if ( convertView == null ) { /*we define the view that will display on the grid*/ //Inflate the layout LayoutInflater li = getLayoutInflater(); MyView = li.inflate(R.layout.griditem, null); // Add The Text!!! TextView tv = (TextView)MyView.findViewById(R.id.grid_item_text); // Add The Image!!! ImageView iv = (ImageView)MyView.findViewById(R.id.grid_item_image); switch(position){ case 0: tv.setText("Universities"); iv.setImageResource(R.drawable.uni); break; case 1: tv.setText("About Us" ); iv.setImageResource(R.drawable.inf); break; case 2: tv.setText("FAQ"); iv.setImageResource(R.drawable.faq); break; case 3: tv.setText("Sample Videos" ); iv.setImageResource(R.drawable.sample); break; case 4: tv.setText("How To Enroll?"); iv.setImageResource(R.drawable.enroll); break; case 5: tv.setText("Benefits" ); iv.setImageResource(R.drawable.benefits); break; } } return MyView; } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return 0; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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