the below code is working from left to right swiping now i would like set the same thing from the right to left also.swiping is working but the speakout is getting crashed with position.in pageAdapter forward swiping is working good.and backward swiping is also working good only but Textto speech is not correctly working
Below is the code:
public Object instantiateItem(ViewGroup container, int position) {
ImageView image=new ImageView(context);
image.setImageResource(fruits[position]);
((ViewPager) container).addView(image);
if(position>=1){
image.setImageResource(fruits[position]);
speakOut(names[position-1]);
}
return image;
}
here its not working. can any one give me suggestions and take me out of this issue
public class Learn extends Activity implements TextToSpeech.OnInitListener{
private TextToSpeech tts;
private ViewPager pic;
private Button next,back;
private TextView text;
private Context context;
private int i=0;
public Integer[] fruits={R.drawable.apple1,R.drawable.banana1,R.drawable.grapes1,R.drawable.cherry1,R.drawable.lemon1,
R.drawable.orange1,R.drawable.strwberry1,R.drawable.water1};
public String [] names={"Apple","Banana","Grapes","Cherry","Lemon","Orange","Strawberry","Water melon"};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.learn);
tts = new TextToSpeech(this, this);
pic=(ViewPager)findViewById(R.id.view_pager);
next=(Button)findViewById(R.id.button1);
back=(Button)findViewById(R.id.button2);
text=(TextView)findViewById(R.id.text);
ImagePageAdapter adapterpic=new ImagePageAdapter(this);
pic.setAdapter(adapterpic);
}
private class ImagePageAdapter extends PagerAdapter {
public ImagePageAdapter(Context learn) {
// TODO Auto-generated constructor stub
context=learn;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return names.length;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView image=new ImageView(context);
image.setImageResource(fruits[position]);
((ViewPager) container).addView(image);
if(position>=1){
image.setImageResource(fruits[position]);
speakOut(names[position-1]);
}
return image;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
private void speakOut(String text) {
// TODO Auto-generated method stub
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
#Override
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
#Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
pic.setEnabled(true);
//speakOut("apple");
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
}
Here is stack trace
02-27 16:39:00.994: I/TTS received:(2369): Apple
02-27 16:39:05.144: I/TTS received:(2369): Banana
02-27 16:39:06.534: I/TTS received:(2369): Grapes
02-27 16:39:24.273: I/TTS received:(2369): Banana
02-27 16:39:25.355: I/TTS received:(2369): Grapes
02-27 16:39:26.593: I/TTS received:(2369): Cherry
02-27 16:39:28.624: I/TTS received:(2369): Apple
please give me suggestions to get out of this issue
why don't you try to put sounds of objects instead of convert them text to speech.. You can try this code
public class Learn extends Activity {
MediaPlayer mp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_numbers);
ViewPager viewPager = (ViewPager)findViewById(R.id.view_pager);
ImagePagerAdapter adapter = new ImagePagerAdapter();
viewPager.setAdapter(adapter);
}
private class ImagePagerAdapter extends PagerAdapter {
private int[] mImages = new int[] {R.drawable.no1,R.drawable.no2,R.drawable.no3,R.drawable.no4,R.drawable.no5,R.drawable.no6,R.drawable.no7,R.drawable.no8,R.drawable.no9,R.drawable.no10,R.drawable.bg2};
private int[] mAudio = new int[]{R.raw.one,R.raw.two,R.raw.three,R.raw.four,R.raw.five,R.raw.six,R.raw.seven,R.raw.eight,R.raw.nine,R.raw.ten,R.raw.one};
#Override
public int getCount() {
return mImages.length;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
Context context = Numbers.this;
ImageView imageView = new ImageView(context);
int padding =context.getResources().
getDimensionPixelSize(R.dimen.activity_vertical_margin);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setImageResource(mImages[position]);
((ViewPager) container).addView(imageView, 0);
if(position>=1){
mp = MediaPlayer.create(Numbers.this, mAudio[position-1]);
mp.start();
}
return imageView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
}
Here value you can change according to your requirements.
Related
I created a "Slide Image" in first activity; which has five images. After I slide the last image(fifth), it should go to next activity,say-activity_next.xml.
Below is my code to slide Image i.e., SlideActivity.java
public class SlideActivity extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
ImagePagerAdapter adapter = new ImagePagerAdapter();
viewPager.setAdapter(adapter);
}
private class ImagePagerAdapter extends PagerAdapter {
private int[] mImages = new int[] {
R.drawable.one,
R.drawable.two,
R.drawable.three,
R.drawable.four,
R.drawable.five
};
#Override
public int getCount() {
return mImages.length;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
Context context = Illustrations.this;
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(
R.dimen.padding_medium);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setImageResource(mImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
}
}
I'm not getting where to pass Intent for next activity i.e., activity_next.xml
**** UPDATED CODE as per your suggestions ****
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
ImagePagerAdapter adapter = new ImagePagerAdapter();
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
// TODO Auto-generated method stub
if(position==viewPager.getAdapter().getCount()){
Intent reg = new Intent(SlideActivity.this,activity_next.class);
startActivity(reg);
}
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
#Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
}
private class ImagePagerAdapter extends PagerAdapter {
private int[] mImages = new int[] {
R.drawable.one,
R.drawable.two,
R.drawable.three,
R.drawable.four,
R.drawable.five
};
#Override
public int getCount() {
return mImages.length+1;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
Context context = Illustrations.this;
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(
R.dimen.padding_medium);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
if(position < getCount()-1)
imageView.setImageResource(mImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
}
****activity_next.java code is below ****
public class activity_next extends Activity{
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_next);
}
}
**** activity_next.xml code is as below****
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to Nowhere Else" />
</LinearLayout>
I'm not getting where to pass Intent for next activity i.e.,
activity_next.xml
To start Activity on reach of last item in ViewPager add OnPageChangeListener to ViewPager and in onPageSelected start next Activity:
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position)
{
if(position==viewPager.getAdapter().getCount()){
//start next Activity here with activity_next.xml layout
}
}
....
});
If you want to slide the last image to go to the next Activity, like a "dismiss" efect, you should try something like this:
private class ImagePagerAdapter extends PagerAdapter {
private int[] mImages = new int[] {
R.drawable.one,
R.drawable.two,
R.drawable.three,
R.drawable.four,
R.drawable.five
};
#Override
public int getCount() {
return mImages.length+1;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
Context context = Illustrations.this;
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(
R.dimen.padding_medium);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
if(position < getCount()-1)
imageView.setImageResource(mImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
and then:
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
ImagePagerAdapter adapter = new ImagePagerAdapter();
viewPager.setAdapter(adapter);
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position)
{
if(position==viewPager.getAdapter().getCount()-1){
//start next Activity
}
}
});
}
I got it clear as #Chol said I just made the count to -1 as below.
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
if(position==viewPager.getAdapter().getCount()-1){
Intent reg = new
Intent(Illustrations.this,Register_Page.class);
startActivity(reg);
}
}
#Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
});
}
Thank you all very much ... :)
The position is image's position that comes array like slide_image[position]. So, with using position, the Intent can be create at the SliderAdapter page just writing several code.
#Override
public Object instantiateItem(final ViewGroup container, final int position) {
layoutInflater =(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.layout, container, false);
LinearLayout layoutslide = view.findViewById(R.id.slider);
ImageView slideImageView =(ImageView)view.findViewById(R.id.slide_image);
TextView slideHeading=(TextView)view.findViewById(R.id.slide_heading);
TextView slideDescription=(TextView)view.findViewById(R.id.slide_desc);
slideImageView.setImageResource(slide_image[position]);
slideHeading.setText(slide_headings[position]);
slideDescription.setText(slide_description[position]);
slideImageView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (position == 0) {
Intent myIntent = new Intent(context,EarthQuakeActivity.class);
context.startActivity(myIntent);
}
if (position == 1) {
Intent myIntent = new Intent(context,EarthQuakeActivity.class);
context.startActivity(myIntent);
}
if (position == 2) {
Intent myIntent = new Intent(context,EarthQuakeActivity.class);
context.startActivity(myIntent);
}
}
});
Is it possible to user View pager without fragments. I google it, and all examples use fragments for view pager. I want to pager load only one item from my list, so I want to ask is it possible. Here is my code for main activity, and I want to use UpdateDisplay for viewpager. Any suggestions.
public class MainActivity extends Activity implements OnClickListener{
private Button prev, next;
private TextView tv;
private int number = 0;
private ArrayList<Integer> numbers;
private ViewPager pager;
private MyPagerAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prev = (Button) findViewById(R.id.prevButton);
prev.setOnClickListener(this);
next = (Button) findViewById(R.id.nextButton);
next.setOnClickListener(this);
numbers = new ArrayList<Integer>();
for (int i=0;i<5;i++){
numbers.add(i);
Log.i("Sljedece elemente dodaje u listu", String.valueOf(i));
}
tv = (TextView) findViewById(R.id.rezultatTextView);
pager = (ViewPager) findViewById(R.id.pager);
adapter = new MyPagerAdapter();
pager.setAdapter(adapter);
updateDIsplay(number);
}
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.prevButton:
number--;
if (number==-1){
number = 4;
}
updateDIsplay(number);
break;
case R.id.nextButton:
number++;
if (number==5){
number = 0;
}
updateDIsplay(number);
break;
}
}
private void updateDIsplay(int z){
tv.setText(String.valueOf(numbers.get(z)));
}
private class MyPagerAdapter extends PagerAdapter{
#Override
public int getCount() {
return numbers.size();
}
#Override
public boolean isViewFromObject(View arg0, Object arg1) {
return false;
}
}
}
yes it possible. Use a PageAdapter. When instantiateItem is called, you can inflate/instantiate your view, and this to the container. E.g:
private class MyPagerAdapter extends PagerAdapter {
#Override
public Object instantiateItem(ViewGroup container, int position) {
TextView view = new TextView(PagerActivity.this);
view.setText("Item "+position);
view.setGravity(Gravity.CENTER);
view.setBackgroundColor(Color.argb(255, position * 50, position * 10, position * 50));
container.addView(view);
return view;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View)object);
}
#Override
public int getCount() {
return 5;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return (view == object);
}
}
I made an app which has 100 pages and change through swipe, but I want to add "Go to page" option so I can go to the specific page easily.
public class ViewPagerExampleActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewpager_example);
ExtendedViewPager mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager);
mViewPager.setAdapter(new TouchImageAdapter());
}
static class TouchImageAdapter extends PagerAdapter {
private static int[] images = { R.drawable.page3, R.drawable.page4,
R.drawable.page5, R.drawable.page6, R.drawable.page7,
R.drawable.page8, R.drawable.page9, R.drawable.page10, R.drawable.page11,
R.drawable.page12, R.drawable.page13, R.drawable.page14,
R.drawable.page15, R.drawable.page16, R.drawable.page17,
R.drawable.page18, R.drawable.page19, R.drawable.page20, R.drawable.page21,
R.drawable.page22, R.drawable.page23, R.drawable.page24,
R.drawable.page25, R.drawable.page26, R.drawable.page27,
R.drawable.page28, R.drawable.page29, R.drawable.page30,
R.drawable.page31, R.drawable.page32, R.drawable.page33, R.drawable.page34,
R.drawable.page35, R.drawable.page36, R.drawable.page37,
R.drawable.page38, R.drawable.page39, R.drawable.page40, R.drawable.page41,
R.drawable.page42, R.drawable.page43, R.drawable.page44,
R.drawable.page45, R.drawable.page46, R.drawable.page47,
R.drawable.page48, R.drawable.page49, R.drawable.page50, R.drawable.page51,
R.drawable.page52, R.drawable.page53, R.drawable.page54,
R.drawable.page55, R.drawable.page56, R.drawable.page57,
R.drawable.page58, R.drawable.page59, R.drawable.page60, R.drawable.page61,
R.drawable.page62, R.drawable.page63, R.drawable.page64,
R.drawable.page65, R.drawable.page66, R.drawable.page67,
R.drawable.page68, R.drawable.page69, R.drawable.page70, R.drawable.page71,
R.drawable.page72, R.drawable.page73, R.drawable.page74 };
#Override
public int getCount() {
return images.length;
}
#Override
public View instantiateItem(ViewGroup container, int position) {
TouchImageView img = new TouchImageView(container.getContext());
img.setImageResource(images[position]);
container.addView(img, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
return img;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
#Override
public void onResume() {
super.onResume();
}
#Override
protected void onPause() {
super.onPause();
}
long lastPress;
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
if (interstitial.isLoaded())
interstitial.show();
}
}
To switch the ViewPager to a specific page, you just need to call setCurrentItem().
I`m trying to implement ImageGallery on Android. I use AndroidTouchGallery library. In MainActyvity I have list of images and by clicking on them open AndroidTouchGallery. Everything work, but when open the image gallery starts with the first one.
There need to set the image position, in which to start. In this stage I have a problem. Maybe someone how to make it.
int pos ; //Picture Position
UrlPagerAdapter pagerAdapter = new UrlPagerAdapter(Full_Image_Activity.this, ArrayImgBig);
mViewPager = (GalleryViewPager)findViewById(R.id.viewer);
mViewPager.setOffscreenPageLimit(3);
mViewPager.setAdapter(pagerAdapter);
The code of UrlPageAdapter. I try to set the position in setPrimaryItem, but it still open the first image.
/**
Class wraps URLs to adapter, then it instantiates {#link UrlTouchImageView} objects to paging up through them.
*/
public class UrlPagerAdapter extends BasePagerAdapter {
public UrlPagerAdapter(Context context, List<String> resources)
{
super(context, resources);
}
#Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
super.setPrimaryItem(container, position, object);
((GalleryViewPager)container).mCurrentView = ((UrlTouchImageView)object).getImageView();
}
#Override
public Object instantiateItem(ViewGroup collection, int position){
final UrlTouchImageView iv = new UrlTouchImageView(mContext);
iv.setUrl(mResources.get(position));
iv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
collection.addView(iv, 0);
return iv;
}
}
BasePagerAdapter
/**
Class wraps URLs to adapter, then it instantiates <b>UrlTouchImageView</b> objects to paging up through them.
*/
public class BasePagerAdapter extends PagerAdapter {
protected final List<String> mResources;
protected final Context mContext;
protected int mCurrentPosition = -1;
protected OnItemChangeListener mOnItemChangeListener;
public BasePagerAdapter()
{
mResources = null;
mContext = null;
}
public BasePagerAdapter(Context context, List<String> resources)
{
this.mResources = resources;
this.mContext = context;
}
#Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
super.setPrimaryItem(container, position, object);
if (mCurrentPosition == position) return;
GalleryViewPager galleryContainer = ((GalleryViewPager)container);
if (galleryContainer.mCurrentView != null) galleryContainer.mCurrentView.resetScale();
mCurrentPosition = position;
if (mOnItemChangeListener != null) mOnItemChangeListener.onItemChange(mCurrentPosition);
}
#Override
public void destroyItem(ViewGroup collection, int position, Object view){
collection.removeView((View) view);
}
#Override
public int getCount()
{
return mResources.size();
}
#Override
public boolean isViewFromObject(View view, Object object){
return view.equals(object);
}
#Override
public void finishUpdate(ViewGroup arg0){
}
#Override
public void restoreState(Parcelable arg0, ClassLoader arg1){
}
#Override
public Parcelable saveState(){
return null;
}
#Override
public void startUpdate(ViewGroup arg0) { }
public int getCurrentPosition() { return mCurrentPosition; }
public void setOnItemChangeListener(OnItemChangeListener listener) { mOnItemChangeListener = listener; }
public static interface OnItemChangeListener
{
public void onItemChange(int currentPosition);
}
}
Olso I have some other queston.
*is the "setPrimaryItem" set up the main Item(Image) witch is open first?
*is the "instantiateItem" initialise every item from the array, whitch is shows?
I made it by this:
mViewPager = (GalleryViewPager)findViewById(R.id.viewer);
mViewPager.setOffscreenPageLimit(3);
mViewPager.setAdapter(pagerAdapter);
//set position
mViewPager.setCurrentItem(pos);
Yesterday, I posted a question about the PagerAdapter and how to achieve it when using database. I managed to sorted it out, however, I do not want the viewpager to swipe/scroll left I want the opposite (swipe to right). The following is my code:
public class ScrollViewTest6 extends ActionBarAppActivity {
private ViewPager awesomePager;
private static int NUM_AWESOME_VIEWS;
private Context cxt;
private AwesomePagerAdapter awesomeAdapter;
TextView tv;
int _id;
int row_numbers;
int row_position;
private DataAdapter mySQLiteAdapter;
private Cursor cursor;
/** Called when the activity is first created. */
#SuppressWarnings("deprecation")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cxt = this;
awesomeAdapter = new AwesomePagerAdapter(awesomeAdapter);
awesomePager = (ViewPager) findViewById(R.id.awesomepager);
awesomePager.setAdapter(awesomeAdapter);
mySQLiteAdapter = new DataAdapter(this);
mySQLiteAdapter.createDatabase();
mySQLiteAdapter.open();
Bundle extras = getIntent().getExtras();
if (extras == null) {
return;
}
_id = extras.getInt("id");
row_numbers = extras.getInt("row_num");
row_position = extras.getInt("row_pos");
NUM_AWESOME_VIEWS = row_numbers;
awesomePager.setCurrentItem(row_position);
cursor = mySQLiteAdapter.get_AllColumns();
this.startManagingCursor(cursor);
this.awesomePager.setOnPageChangeListener(new ViewPager.OnPageChangeListener()
{
#Override
public void onPageScrollStateChanged(int arg0) {
}
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels){
}
#Override
public void onPageSelected(int position){
}
});
}
private class AwesomePagerAdapter extends PagerAdapter{
public AwesomePagerAdapter(PagerAdapter fm) {
}
#Override
public int getCount() {
return NUM_AWESOME_VIEWS;
}
#Override
public int getItemPosition(Object object) {return POSITION_NONE;}
#Override
public Object instantiateItem(ViewGroup collection, int position) {
LayoutInflater inflater = (LayoutInflater)cxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.mylayout, null);
TextView Title = (TextView)layout.findViewById(R.id.title);
if (cursor != null ) {
if (cursor.moveToPosition(position)) {
//do {
//cursor.moveToPosition(position);
String text = cursor.getString(
cursor.getColumnIndexOrThrow(DataAdapter.KEY_Title));
Title.setText(text);
}
}
((ViewPager) collection).addView(layout,0);
return layout;
}
#Override
public void destroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((View) view);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view==((View)object);
}
#Override
public void finishUpdate(View arg0) {
}
#Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}
#Override
public Parcelable saveState() {
return null;
}
#Override
public void startUpdate(View arg0) {
}
}
}
I know some people suggest using
setCurrentItem(int); //Last page
But that conflicts with the listview order.
e.g. Listview:
1
2
3
when we use the line above it shows 1 <- 2 <- 3 (starting from 3)
and I want 3 <- 2 <- 1 (starting from 1)
I face this issue and I resolve with this library
use it and your pagination will work right to left perfectly
it work same as ViewPager
https://github.com/diego-gomez-olvera/RtlViewPager
<com.booking.rtlviewpager.RtlViewPager
android:id="#+id/arabicViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
arabicViewPager = (ViewPager) findViewById(R.id.arabicViewPager);
adapterViewPager = new Adpt_fragmentPageAdapter(getSupportFragmentManager());
arabicViewPager.setAdapter(adapterViewPager);
tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(arabicViewPager);
Thanks to AleksG
Here is what he suggested to do which works for the required purpose, so add the following line to the list:
setCurrentItem(count - 1)
Then in the cursor you'll need to set up the list order in the cursor "_desc"
Thanks again.