Android image click in horizontal page view
Posted
by
JaseemAmeer
on Stack Overflow
See other posts from Stack Overflow
or by JaseemAmeer
Published on 2012-03-28T07:49:25Z
Indexed on
2012/03/31
5:29 UTC
Read the original article
Hit count: 555
I've implemented horizontal page view with many images. And I'm trying to create a click event on the image.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pbase);
ImageView binfo,bheacno;
tvHeacno=(TextView) findViewById(R.id.tvheacno);
heacno=getHeacno();
tvHeacno.setText(heacno);
MyPagerAdapter adapter=new MyPagerAdapter();
ViewPager myPager=(ViewPager)findViewById(R.id.mythreepanelpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);
binfo=(ImageView) findViewById(R.id.ivinfo);
bheacno=(ImageView) findViewById(R.id.ivheacno);
binfo.setOnClickListener(this);
bheacno.setOnClickListener(this);
}
then i've MyPagerAdapter class and the onclik method. it returns null to binfo and hence fails at binfo.setOnClickListener(this) I've done image click before on normal pages successfully. Is it because of horizontal page views? How can I solve this issue??
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:layout_weight="33"
android:layout_gravity="top" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:layout_weight="33"
android:layout_gravity="center_horizontal" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:gravity="center" android:layout_weight="50"
android:id="@+id/ivinfo" android:layout_width="wrap_content"
android:layout_gravity="center" android:layout_height="wrap_content"
android:src="@drawable/information" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="@android:color/black"
android:layout_weight="50" android:layout_gravity="center"
android:gravity="center" android:text=" Information " />
</LinearLayout>
<LinearLayout android:layout_weight="33"
android:layout_gravity="center_horizontal" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:gravity="center" android:layout_weight="50"
android:id="@+id/ivheacno" android:layout_width="wrap_content"
android:layout_gravity="center" android:layout_height="wrap_content"
android:src="@drawable/heacno" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="@android:color/black"
android:layout_weight="50" android:layout_gravity="center"
android:gravity="center" android:text="Get HEAC Number" />
</LinearLayout>
<LinearLayout android:layout_weight="33"
android:layout_gravity="center_horizontal" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:gravity="center" android:layout_weight="50"
android:id="@+id/ivpi" android:layout_width="wrap_content"
android:layout_gravity="center" android:layout_height="wrap_content"
android:src="@drawable/pi" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="@android:color/black"
android:layout_weight="50" android:layout_gravity="center"
android:gravity="center" android:text="Personal Information" />
</LinearLayout>
</LinearLayout>
<LinearLayout android:layout_weight="33"
android:layout_gravity="center" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:layout_weight="33"
android:layout_gravity="left" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:gravity="center" android:layout_weight="50"
android:id="@+id/ivassn" android:layout_width="wrap_content"
android:layout_gravity="center" android:layout_height="wrap_content"
android:src="@drawable/assn" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="@android:color/black"
android:layout_weight="50" android:layout_gravity="center"
android:gravity="center" android:text="Add Social Security Number" />
</LinearLayout>
<LinearLayout android:layout_weight="33"
android:layout_gravity="left" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:gravity="center" android:layout_weight="50"
android:id="@+id/ivvssn" android:layout_width="wrap_content"
android:layout_gravity="center" android:layout_height="wrap_content"
android:src="@drawable/vssn" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="@android:color/black"
android:layout_weight="50" android:layout_gravity="center"
android:gravity="center" android:text="View Social Security Number" />
</LinearLayout>
<LinearLayout android:layout_weight="33"
android:layout_gravity="left" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:gravity="center" android:layout_weight="50"
android:id="@+id/ivdssn" android:layout_width="wrap_content"
android:layout_gravity="center" android:layout_height="wrap_content"
android:src="@drawable/dssn" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="@android:color/black"
android:layout_weight="50" android:layout_gravity="center"
android:gravity="center" android:text="Delete Social Security Number" />
</LinearLayout>
</LinearLayout>
<LinearLayout android:layout_weight="33"
android:layout_gravity="bottom" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:layout_weight="33"
android:layout_gravity="left" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:gravity="center" android:layout_weight="50"
android:id="@+id/ivali" android:layout_width="wrap_content"
android:layout_gravity="center" android:layout_height="wrap_content"
android:src="@drawable/ali" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="@android:color/black"
android:layout_weight="50" android:layout_gravity="center"
android:gravity="center" android:text="Add Low Income" />
</LinearLayout>
<LinearLayout android:layout_weight="33"
android:layout_gravity="left" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:gravity="center" android:layout_weight="50"
android:id="@+id/ivvli" android:layout_width="wrap_content"
android:layout_gravity="center" android:layout_height="wrap_content"
android:src="@drawable/vli" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="@android:color/black"
android:layout_weight="50" android:layout_gravity="center"
android:gravity="center" android:text="View Low Income" />
</LinearLayout>
<LinearLayout android:layout_weight="33"
android:layout_gravity="left" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:gravity="center" android:layout_weight="50"
android:id="@+id/ivdli" android:layout_width="wrap_content"
android:layout_gravity="center" android:layout_height="wrap_content"
android:src="@drawable/dli" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="@android:color/black"
android:layout_weight="50" android:layout_gravity="center"
android:gravity="center" android:text="Delete Low Income" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
© Stack Overflow or respective owner