| 21478 |
rajender |
1 |
package com.saholic.profittill.Utils;
|
|
|
2 |
|
|
|
3 |
import android.content.Context;
|
|
|
4 |
import android.support.v4.view.PagerAdapter;
|
|
|
5 |
import android.view.LayoutInflater;
|
|
|
6 |
import android.view.View;
|
|
|
7 |
import android.view.ViewGroup;
|
|
|
8 |
import android.widget.ImageView;
|
|
|
9 |
import android.widget.RelativeLayout;
|
|
|
10 |
import android.widget.TextView;
|
|
|
11 |
|
|
|
12 |
import com.saholic.profittill.R;
|
|
|
13 |
|
|
|
14 |
public class CustomPageAdapter extends PagerAdapter {
|
|
|
15 |
// Declare Variables
|
|
|
16 |
Context context;
|
|
|
17 |
String[] rank;
|
|
|
18 |
String[] openingText;
|
|
|
19 |
String[] middleText;
|
|
|
20 |
int[] flag;
|
|
|
21 |
|
|
|
22 |
LayoutInflater inflater;
|
|
|
23 |
|
|
|
24 |
public CustomPageAdapter(Context context, String[] rank,int[] flag,String[] openingText,String[] middleText) {
|
|
|
25 |
this.context = context;
|
|
|
26 |
this.flag = flag;
|
|
|
27 |
this.rank = rank;
|
|
|
28 |
this.openingText = openingText;
|
|
|
29 |
this.middleText = middleText;
|
|
|
30 |
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
@Override
|
|
|
34 |
public int getCount() {
|
|
|
35 |
return rank.length;
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
@Override
|
|
|
39 |
public boolean isViewFromObject(View view, Object object) {
|
|
|
40 |
return view == object;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
@Override
|
|
|
44 |
public Object instantiateItem(ViewGroup container, int position) {
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
ImageView imgflag;
|
|
|
48 |
TextView openingTextView, middleTextView;
|
|
|
49 |
inflater = (LayoutInflater) context
|
|
|
50 |
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
51 |
View itemView = inflater.inflate(R.layout.viewpager_item, container,
|
|
|
52 |
false);
|
|
|
53 |
|
|
|
54 |
openingTextView= (TextView) itemView.findViewById(R.id.openingText);
|
|
|
55 |
middleTextView= (TextView) itemView.findViewById(R.id.secondText);
|
|
|
56 |
imgflag = (ImageView) itemView.findViewById(R.id.flag);
|
|
|
57 |
openingTextView.setText(openingText[position]);
|
|
|
58 |
middleTextView.setText(middleText[position]);
|
|
|
59 |
imgflag.setImageResource(flag[position]);
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
container.addView(itemView);
|
|
|
63 |
|
|
|
64 |
return itemView;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
@Override
|
|
|
68 |
public void destroyItem(ViewGroup container, int position, Object object) {
|
|
|
69 |
// Remove viewpager_item.xml from ViewPager
|
|
|
70 |
container.removeView((RelativeLayout) object);
|
|
|
71 |
|
|
|
72 |
}
|
|
|
73 |
}
|