I'm implementing view pager as row in list-view. I have done the adding view pager in List View, But the problem is I'm adding the pages in view pager whatever return SQLite count Function.If count is 3 so show the images in View Pager 3 and If count is 5 so show the images in View Pager 5 . But getting error of StackOverFlowError.I have tried on best level last 2 to 3 days but not work perfectly.Can someone help me.How to do this.
hare is my Activity code
public void getActivityObjectId_Count() {
try {
dbhelper = new MyDbHelper(this);
SQLiteDatabase db = dbhelper.getReadableDatabase();
Cursor cursor2 = db.rawQuery("select count(activityObjId) from ActivityObjectList where " + "activityId" + " = ?", new String[]{strDescription});
if (cursor2 != null) {
cursor2.moveToFirst();
String strCount_ActivityObjectId = cursor2.getString(0);
intCount = Integer.parseInt(strCount_ActivityObjectId);
Log.e("intCount", "in getActivityObjectId = " + intCount);
}
cursor2.close();
db.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
class MyListAdapter extends ArrayAdapter<all_post> {
Context context;
int layoutResourceId;
private int selectedIndex;
ArrayList<all_post> data = new ArrayList<all_post>();
public MyListAdapter(Context context, int layoutResourceId, ArrayList<all_post> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public int getCount()
{
notifyDataSetChanged();
return data.size();
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
Holder holder = null;
if (row == null)
{
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new Holder();
holder.txt_Descid = (TextView) row.findViewById(R.id.textDescid);
holder.txtTitle = (TextView) row.findViewById(R.id.txt_Desc);
holder.txtInitialLetter = (TextView) row.findViewById(R.id.txt_InitialLetter);
holder.txtRemark = (TextView) row.findViewById(R.id.textRemark);
holder.imgBtn_Rework = (ImageView) row.findViewById(R.id.imgButtonRework);
holder.imgBtn_FollowUp = (ImageView) row.findViewById(R.id.imgButtonFoloowUp);
holder.imgBtn_RateEquipMent = (ImageView) row.findViewById(R.id.imgButtonRateEquipment);
holder.imgBtn_Camera = (ImageView) row.findViewById(R.id.imgButtonCamera);
holder.imgBtn_Audio = (ImageView) row.findViewById(R.id.imgButtonAudio);
holder.imgBtn_FollowInspector = (ImageView) row.findViewById(R.id.imgButtonFollowInspector);
holder.viewPager = (ViewPager) row.findViewById(R.id.Image_ViewPagers);
holder.viewPager.setPageMargin(-50);
holder.viewPager.setHorizontalFadingEdgeEnabled(true);
holder.viewPager.setFadingEdgeLength(20);
holder.viewPager.setClipToPadding(false);
holder.viewPager.setPadding(-5, 0, 0, 0);
MyPagerAdapter adapter = new MyPagerAdapter(getContext());
holder.viewPager.setAdapter(adapter);
holder.viewPager.setCurrentItem(0);
adapter.notifyDataSetChanged();
//holder.viewPager.getAdapter().notifyDataSetChanged();
row.setTag(holder);
} else {
holder = (Holder) row.getTag();
}
All_Post all_Post = data.get(position);
holder.txt_Descid.setText(Integer.toString(all_Post.getID()));
String strTextDescId = holder.txt_Descid.getText().toString().trim();
Log.e("strTextDescId ", " = " + strTextDescId);
getActivityId(strTextDescId);
getActivityObjectId_Count();
holder.txtTitle.setText(all_Post.getName());
String strTxtTitle = holder.txtTitle.getText().toString().trim();
Log.e("strTxtTitle ", " = " + strTxtTitle);
holder.txtInitialLetter.setText(all_Post.getInitName());
holder.txtRemark.setText(all_Post.getStrDesc());
holder.imgBtn_Rework.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("Button click ", "event is fire");
}
});
return row;
}
class Holder {
TextView txt_Descid;
TextView txtTitle;
TextView txtInitialLetter;
TextView txtRemark;
ViewPager viewPager;
ImageView imgBtn_Rework;
ImageView imgBtn_FollowUp;
ImageView imgBtn_RateEquipMent;
ImageView imgBtn_Camera;
ImageView imgBtn_Audio;
ImageView imgBtn_FollowInspector;
}
}
class MyPagerAdapter extends PagerAdapter {
Context mContent;
LayoutInflater mLayoutInflater;
private List<string> testImages = new ArrayList<string>();
private int[] GalImages = new int[]{
R.drawable.img_placeholder,
R.drawable.img_placeholder,
R.drawable.img_placeholder,
R.drawable.img_placeholder,
R.drawable.img_placeholder,
R.drawable.img_placeholder
};
public MyPagerAdapter(Context context) {
super();
mContent = context;
mLayoutInflater = (LayoutInflater) mContent.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public float getPageWidth(int position) {
return 0.9f;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
// TODO Auto-generated catch block
ImageView imageView = new ImageView(mContent);
imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setImageResource(GalImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
@Override
public int getCount() {
// return PAGE_NUM;
Log.e("intCount8888: "," = " +intCount );
notifyDataSetChanged();
return intCount;
}
@Override
public boolean isViewFromObject(View view, Object obj) {
//return view.equals(obj);
return view == ((ImageView) obj);
}
}
Here is my LogCat information
08-07 02:20:38.436 3096-3096/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.StackOverflowError
at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:801)
at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:5998)
at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getCount(AllPosts_Page.java:399)
at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:801)
at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:5998)
at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getCount(AllPosts_Page.java:399)
at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:801)
at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:5998)
at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getCount(AllPosts_Page.java:399)
at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:801)
at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:5998)
at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getCount(AllPosts_Page.java:399)
at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:801)
at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:5998)
at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getCount(AllPosts_Page.java:399)
at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:801)
at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:5998)
at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getCount(AllPosts_Page.java:399)
at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:801)
at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:5998)
at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getCount(AllPosts_Page.java:399)
at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:801)
at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:5998)
at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getCount(AllPosts_Page.java:399)
at android.widget.AdapterView$AdapterDataSetObs