I am trying to implement a ViewPager inside a Dialog, I used the technique proposed here: http://stackoverflow.com/a/18710611/5482015 .The compiler does not show any error but nothing is displayed when running the app.
dialog layout xml file
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="200dp" android:layout_height="200dp" android:background="#fff" > <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/page_one" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#f2a"> <TextView android:text="PAGE ONE IN" android:layout_width="match_parent" android:layout_height="match_parent" android:textColor="#000" android:background="#f2a" android:textSize="24dp"/> </LinearLayout> <LinearLayout android:id="@+id/page_two" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#2f1"> <TextView android:text="PAGE TWO IN" android:layout_width="match_parent" android:layout_height="match_parent" android:textColor="#000" android:background="#2f1" android:textSize="24dp"/> </LinearLayout> </android.support.v4.view.ViewPager> </LinearLayout> the custom dialog
import android.app.Activity; import android.app.Dialog; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.Button; public class CustomDialogClass extends Dialog implements OnClickListener { public Activity c; public Dialog d; public CustomDialogClass(Activity a) { super(a); // TODO Auto-generated constructor stub this.c = a; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.custom_dialog); } @Override public void onClick(View v) { } } the call of the custom dialog and the adapter
protected void onCreate(Bundle savedInstanceState) { ... findViewById(R.id.howto).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CustomDialogClass cdd = new CustomDialogClass(mainActivity.this); cdd.show(); WizardPagerAdapter adapter = new WizardPagerAdapter(); ViewPager pager = (ViewPager)cdd. findViewById(R.id.pager); pager.setAdapter(adapter); } } The adapter is an inner class in mainActivity
class WizardPagerAdapter extends PagerAdapter { public Object instantiateItem(View collection, int position) { int resId = 0; switch (position) { case 0: resId = R.id.page_one; break; case 1: resId = R.id.page_two; break; } return findViewById(resId); } @Override public int getCount() { return 2; } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == ((View) arg1); } @Override public void destroyItem(View arg0, int arg1, Object arg2) { } } Thanking you in advance.
No comments:
Post a Comment