Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid viewpager plus imageview
    primarykey
    data
    text
    <p>I'm trying to create an Android app which will work in the following manner:</p> <p>I have a ViewPager item loaded with 10 images: that isn't a problem.</p> <p>Now, when I click into the image shown in the ViewPager, I must display it on an ImageView field below the ViewPager.</p> <p>How do I implement the method to copy the image from the ViewPager to the ImageView?</p> <p>Here is my code:</p> <p><strong>SecondActivity.java</strong></p> <pre><code>package com.example.logger; import android.os.Bundle; import android.annotation.SuppressLint; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.widget.ImageView; import android.view.ViewGroup; public class SecondActivity extends Activity { private static final int NUM_PAGES = 10; private ViewPager mpager; private MyPagerAdapter mPagerAdapter; private int [] pics = {R.drawable.android_interfaz_layout_estructura_final, R.drawable.baixa, R.drawable.baixada, R.drawable.greenprogressbar, R.drawable.layout_keyboard, R.drawable.linerlay, R.drawable.merge1, R.drawable.o2zds, R.drawable.regbd, R.drawable.s7qrs}; @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); mPagerAdapter = new MyPagerAdapter(); mpager = (ViewPager) findViewById(R.id.viewer); mpager.setAdapter (mPagerAdapter); } private class MyPagerAdapter extends PagerAdapter { @Override public int getCount() { // TODO Auto-generated method stub return pics.length; } @Override public boolean isViewFromObject(View arg0, Object arg1) { // TODO Auto-generated method stub return false; } @Override public Object instantiateItem(View collection, int position) { ImageView view = new ImageView (SecondActivity.this); view.setImageResource (pics[position]); ((ViewPager) collection).addView(view, 0); return view; } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.second, menu); return true; } public void onClick (View v) { // TODO Auto-generated method stub //aquí anirà la funció per traslladar la image de la gallery a la pantalla mpager.setVisibility(View.VISIBLE); mpager.setCurrentItem(v.getId()); } } </code></pre> <p><strong>End .java</strong></p> <p>And here is my layout as well:</p> <p><strong>activity_second.xml</strong></p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" 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=".SecondActivity" &gt; &lt;android.support.v4.view.ViewPager android:padding="16dp" android:id="@+id/viewer" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_weight="0.70" /&gt; &lt;ImageView android:id="@+id/big_image" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_below="viewer" android:layout_weight="0.30" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p><strong>end .xml</strong></p> <p>I would be very grateful if you could help me out.</p> <p>Yours sincerely,</p> <p>Mauro.</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.
    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