Note that there are some explanatory texts on larger screens.

plurals
  1. POSwitching between two GridViews in the same Activity
    primarykey
    data
    text
    <p>I've been looking around how to solve several problems and got several answers to some of my question, but one thing is still under construction and won't be finished if none of you can help me. :/</p> <p>I've been trying to zoom in and out of a GridView, but got over to an other solution, since I do only need two states: an overview and a detailed view. Therefor I've made two Gridviews. The first one is the one where the images inside both gridviews are shrunk and displayed without scrolling. The other one is the one where the images are displayed in their original size. You can scroll horizontally and vertically inside that one.</p> <p>My problem is the switching between those two gridviews. I've tried to "set the visibility" of both to either "gone" or "visible" if i clicked on one of them.</p> <p>Here's my code:</p> <p>Starter:</p> <pre><code>package test.scroll; import android.app.Activity; import android.os.Bundle; import android.widget.GridView; import android.view.View; import android.view.View.OnClickListener; public class TestScrollActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final GridView grd_overview = (GridView)this.findViewById(R.id.grd_overview); grd_overview.setAdapter(new OverviewImageAdapter(this)); final GridView grd_detailed = (GridView)this.findViewById(R.id.grd_detailed); grd_detailed.setVisibility(2); grd_detailed.setAdapter(new DetailedImageAdapter(this)); grd_overview.setOnClickListener(new OnClickListener() { public void onClick(View view) { grd_overview.setVisibility(2); grd_detailed.setVisibility(0); } }); grd_detailed.setOnClickListener(new OnClickListener() { public void onClick(View view) { grd_detailed.setVisibility(2); grd_overview.setVisibility(0); } }); } } </code></pre> <p>OverviewAdapter:</p> <pre><code>package test.scroll; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; public class OverviewImageAdapter extends BaseAdapter { private Context mContext; public OverviewImageAdapter(Context c) { mContext = c; } public int getCount() { return mThumbIds.length; } public Object getItem(int position) { return null; } public long getItemId(int position) { return 0; } // create a new ImageView for each item referenced by the Adapter public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView; if (convertView == null) { // if it's not recycled, initialize some attributes imageView = new ImageView(mContext); imageView.setLayoutParams(new GridView.LayoutParams(82, 82)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); } else { imageView = (ImageView) convertView; } imageView.setImageResource(mThumbIds[position]); return imageView; } // references to our images private Integer[] mThumbIds = { R.drawable.memory_1, R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1, R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1, R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1, R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1, R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1, R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1,R.drawable.memory_1 }; } </code></pre> <p>DetailedAdapter:</p> <pre><code>package test.scroll; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; public class DetailedImageAdapter extends BaseAdapter { private Context mContext; public DetailedImageAdapter(Context c) { mContext = c; } public int getCount() { return mThumbIds.length; } public Object getItem(int position) { return null; } public long getItemId(int position) { return 0; } // create a new ImageView for each item referenced by the Adapter public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView; if (convertView == null) { // if it's not recycled, initialize some attributes imageView = new ImageView(mContext); imageView.setLayoutParams(new GridView.LayoutParams(82, 82)); } else { imageView = (ImageView) convertView; } imageView.setImageResource(mThumbIds[position]); return imageView; } // references to our images private Integer[] mThumbIds = { R.drawable.memory_2, R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2, R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2, R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2, R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2, R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2, R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2,R.drawable.memory_2 }; } </code></pre> <p>XML:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/app_layout" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;!-- PLAYGROUND --&gt; &lt;test.scroll.TwoDScrollView android:id="@+id/scene_scroller" android:drawingCacheQuality="low" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:id="@+id/grds" android:drawingCacheQuality="low" android:layout_width="fill_parent" android:layout_height="wrap_content" &gt; &lt;GridView android:id="@+id/grd_overview" android:drawingCacheQuality="low" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;GridView android:id="@+id/grd_detailed" android:drawingCacheQuality="low" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; &lt;/test.scroll.TwoDScrollView&gt; &lt;!-- ATTRIBUTES --&gt; &lt;Button android:id="@+id/btn_cancel" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/scene_scroller" android:text="cancel" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Do you have any suggestions for me on how to switch between those two gridview? Let me know :)</p> <p>Basti</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