Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid GridView Item Order Change when Admob displays
    primarykey
    data
    text
    <p>I searched for these issues and tried most of the given answers but my issue is not solved yet. My Grid view has around 10-12 items and and each item has a ImageView and a TextView. image and the texts are dynamically loading from resources. </p> <p>Issue 1 : When the grid is scrolling the item order changes. first items goes to down and the last items coming to top</p> <p>Issue 2: When an Admob ad loads in the bottom of the screen entire Grid items are mixing up.Even without any scrolling.</p> <p>Issue 3: Currently I have put the onClickListeners to the ImageView Only. How do I add the same OnclickListener to the relevant TextView as well</p> <p>I have used a common gridview generation code found every where in the net.</p> <p>Here is my code</p> <pre><code>public class ImageAdapter extends BaseAdapter{ Context myContext; public ImageAdapter(Context _myContext){ myContext = _myContext; } @Override public View getView(final int position, View convertView, ViewGroup parent) { View MyView = convertView; try{ if ( convertView == null ){ LayoutInflater li = ((Activity)myContext).getLayoutInflater(); MyView = li.inflate(R.layout.weather_grid, null); TextView tv = (TextView)MyView.findViewById(R.id.grid_item_text); Resources res = getResources(); String[] items = res.getStringArray(R.array.weather_items); final String[] titles = new String[items.length]; int x = 0; for(String item:items){ titles[x]=item; x++; } // getStringFromRes(titles[position]); tv.setText(titles[position]); // Add The Image!!! final ImageView iv = (ImageView)MyView.findViewById(R.id.grid_item_image); Class&lt;drawable&gt; resources = R.drawable.class; Field[] fields = resources.getFields(); String[] imageName = new String[fields.length]; int index = 0; for( Field field : fields ) { if(field.getName().startsWith("weather")){ imageName[index] = field.getName(); index++; } } iv.setImageResource(getDrawable(myContext, imageName[position])); iv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { System.out.println("Clicked Item = " + titles[position]); Bundle b = new Bundle(); if(titles[position].equals("Weather Overview")){ startActivity(new Intent(WeatherGridActivity.this, WeatherActivity.class)); } if(titles[position].equals("Current Weather")){ b.putString("display", "current"); Intent intent = new Intent(WeatherGridActivity.this,WeatherActivity.class); intent.putExtras(b); startActivityForResult(intent, 0); //startActivity(new Intent(WeatherGridActivity.this, WeatherActivity.class)); } if(titles[position].equals("Ask a Question")){ startActivity(new Intent(WeatherGridActivity.this, AskQuestionActivity.class)); } if(titles[position].equals("Average Temperature")){ startActivity(new Intent(WeatherGridActivity.this, AverageTemperatureActivity.class)); } } }); } }catch(Exception e){ System.out.println("Error Occured = " + e.getMessage()); e.printStackTrace(); } 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; } @Override public int getCount() { return 10; } public int getDrawable(Context context, String name){ Assert.assertNotNull(context); Assert.assertNotNull(name); return context.getResources().getIdentifier(name,"drawable", context.getPackageName()); } public String getStringFromRes(String name){ try{ int resId = (Integer) R.string.class.getField(name).get(null); // Toast.makeText(MyContext, getResources().getString(resId), Toast.LENGTH_LONG).show(); return getResources().getString(resId); }catch(Exception e){ // no such string return "empty"; } } } </code></pre> <p>Here is the xml</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/bg" android:orientation="vertical" &gt; &lt;GridView android:id="@+id/weather" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg" android:columnWidth="70dp" android:gravity="center_horizontal" android:horizontalSpacing="20dp" android:numColumns="auto_fit" android:padding="20dp" android:stretchMode="columnWidth" android:tileMode="repeat" android:verticalSpacing="20dp" &gt; &lt;/GridView&gt; &lt;ImageView android:id="@+id/back_button" style="@style/book_button" /&gt; &lt;com.google.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" ads:adSize="BANNER" ads:adUnitId="dummy id" ads:loadAdOnCreate="true" ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" /&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; </code></pre> <p>I have added the RelativeLayout instead of LinerLayout and ScrollViews but now the entire Grid doesn't display but the ads displaying properly. Here is the new xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:id="@+id/home_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/bg" &gt; &lt;GridView android:id="@+id/home_grid" android:layout_width="wrap_content" android:layout_height="0dip" android:columnWidth="100dp" android:rowHeight="30dp" android:gravity="center_horizontal" android:horizontalSpacing="5dp" android:numColumns="auto_fit" android:stretchMode="none" android:tileMode="repeat" android:verticalSpacing="30dp" &gt; &lt;/GridView&gt; &lt;com.google.ads.AdView android:layout_alignParentBottom="true" android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adSize="BANNER" ads:adUnitId="dummy id" ads:loadAdOnCreate="true" ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" android:layout_centerHorizontal="true" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Your answers are highly appreciated Thanks </p>
    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.
 

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