我需要你的幫助,同時將數據設置爲列表視圖中的列表項目。在我的listview中,每個項目都有一個ViewPager,每個viewpager應該有不同的數據。我沒有得到如何爲每個viewpager設置不同的數據。實際上,基於listitem索引,我需要設置數據viewpager。請通過我的代碼片段粘貼下面,並試圖幫助我。listview在android中的每個列表項目中有viewpager
public class MyListAdapter extends BaseAdapter {
private Activity activity;
private String [] titleData;
private int [] imageData;
private static LayoutInflater inflater=null;
private int iListPosition;
private GraphicalView graphView ;
ListView dashListView;
private Context context;
public MyListAdapter(View listView, Activity a, String[] titles, int[] images) {
activity = a;
context = a.getApplicationContext();
dashListView = (ListView)listView;
}
public int getCount() {
return titleData.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
iListPosition = position;
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) activity.getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.dash_board_list_row, parent, false);
MyPagerAdapter adapter = new MyPagerAdapter();
ViewPager myPager = (ViewPager) rowView.findViewById(R.id.threepageviewer);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);
return rowView;
}
private class MyPagerAdapter extends PagerAdapter {
public int getCount() {
return 3;
}
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0:
resId = R.layout.weight_middle;
break;
case 1:
resId = R.layout.weight_left;
break;
case 2:
resId = R.layout.weight_right;
break;
}
View view = inflater.inflate(resId, null);
if(resId == R.layout.weight_left && iListPosition == 0){
LinearLayout layout = (LinearLayout) view.findViewById(R.id.chartView);
layout.addView(graphView);
}
((ViewPager) collection).addView(view, 0);
return view;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
@Override
public void finishUpdate(View arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
// TODO Auto-generated method stub
}
@Override
public Parcelable saveState() {
// TODO Auto-generated method stub
return null;
}
@Override
public void startUpdate(View arg0) {
// TODO Auto-generated method stub
}
}
}
但是,這裏相同的數據將geting設置爲所有列表項的Viewpage。理想情況下,我的要求是設置不同的數據。請讓我知道,如果你有/知道任何解決方案。