ViewPager Activity change content when slide - android

I've been looking around but I can't figure out how I can fixed this issue.
I'm using the #Dave Morrissey's Subsampling Zoom Image View, is a great library and it works perfect, but I want to do a few changes.
For each image that the user will slide I want show the specific description.
So it will be:
Pic1 |Pic2 |Pic3
DescriptionPic1 |DescriptionPic2 |DescriptionPic3
When I open it I can see the picture with below the right description but when I slide left(or right) I can see always the description of the item after.
Happens because the method getItem() get called twice to make the slider more smooth.
The problem is that I want show the right content(description) below each picture.
How can I show the content perfectly when the user slide the pics?
Any help is really appreciate.
Thanks guys
ViewPagerActivity.java
public class ViewPagerActivity extends FragmentActivity {
private ViewPager page;
private Bitmap bmImg1;
private Bitmap bmImg2;
private Bitmap bmImg3;
private String TAG;
ArrayList<Bitmap> IMAGES =new ArrayList<Bitmap>();
String[] descriptionPhoto;
int numpics=1;
private int position_pic;
private String suggested_aperture;
private String suggested_filter;
private String suggested_iso;
private String suggested_shutter;
private String suggested_shot_level;
private String suggested_lens;
private String[] shot_levelPhoto;
private String[] filterPhoto;
private String[] aperturePhoto;
private String[] shutterPhoto;
private String[] isoPhoto;
private String[] focal_lengthPhoto;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_pager);
FileInputStream fis;
FileInputStream fis2;
FileInputStream fis3;
Bundle intent=getIntent().getExtras();
descriptionPhoto = intent.getStringArray("descriptionPhoto");
numpics = (int) intent.get("numpics");
position_pic = (int) intent.get("position_pic");
suggested_aperture= intent.getString("suggested_aperture");
suggested_filter= intent.getString("suggested_filter");
suggested_iso= intent.getString("suggested_iso");
suggested_shutter= intent.getString("suggested_shutter");
suggested_shot_level= intent.getString("suggested_shot_level");
suggested_lens= intent.getString("suggested_lens");
shot_levelPhoto=intent.getStringArray("shot_levelPhoto");
filterPhoto =intent.getStringArray("filterPhoto");
aperturePhoto =intent.getStringArray("aperturePhoto");
shutterPhoto =intent.getStringArray("shutterPhoto");
isoPhoto =intent.getStringArray("isoPhoto");
focal_lengthPhoto=intent.getStringArray("focal_lengthPhoto");
TextView txtaperture_suggested = (TextView) findViewById(R.id.aperture_suggested);
TextView txtfilter_suggested = (TextView) findViewById(R.id.filter_suggested);
TextView txtiso_suggested = (TextView) findViewById(R.id.iso_suggested);
TextView txtlens_suggested = (TextView) findViewById(R.id.lens_suggested);
TextView txtshutter_suggested = (TextView) findViewById(R.id.shutter_suggested);
TextView txtshot_levelsuggested = (TextView) findViewById(R.id.shot_levelsuggested);
if (suggested_shot_level == "1") {
txtshot_levelsuggested.setText("Easy");
/*txtshot_levelPhoto2.setText("Easy");
txtshot_levelPhoto3.setText("Easy");*/
} else if (suggested_shot_level == "2") {
txtshot_levelsuggested.setText("Medium");
/* txtshot_levelPhoto2.setText("Medium");
txtshot_levelPhoto3.setText("Medium");*/
} else if (suggested_shot_level == "3") {
txtshot_levelsuggested.setText("Difficult");
/*txtshot_levelPhoto2.setText("Difficult");
txtshot_levelPhoto3.setText("Difficult");*/
} else {
txtshot_levelsuggested.setText("Pro");
/* txtshot_levelPhoto2.setText("Pro");
txtshot_levelPhoto3.setText("Pro");*/
}
txtaperture_suggested.setText(suggested_aperture);
txtfilter_suggested.setText(suggested_filter);
txtiso_suggested.setText(suggested_iso);
txtshutter_suggested.setText(suggested_shutter);
txtlens_suggested.setText(suggested_lens);
TextView txtshutterPhoto = (TextView) findViewById(R.id.shutterPhoto);
TextView txtshutterPhoto2 = (TextView) findViewById(R.id.shutterPhoto2);
TextView txtshutterPhoto3 = (TextView) findViewById(R.id.shutterPhoto3);
TextView txtshot_levelPhoto = (TextView) findViewById(R.id.shot_levelPhoto);
TextView txtshot_levelPhoto2 = (TextView) findViewById(R.id.shot_levelPhoto2);
TextView txtshot_levelPhoto3 = (TextView) findViewById(R.id.shot_levelPhoto3);
TextView txtaperturePhoto = (TextView) findViewById(R.id.aperturePhoto);
TextView txtaperturePhoto2 = (TextView) findViewById(R.id.aperturePhoto2);
TextView txtaperturePhoto3 = (TextView) findViewById(R.id.aperturePhoto3);
TextView txtfilterPhoto = (TextView) findViewById(R.id.filterPhoto);
TextView txtfilterPhoto2 = (TextView) findViewById(R.id.filterPhoto2);
TextView txtfilterPhoto3 = (TextView) findViewById(R.id.filterPhoto3);
TextView txtisoPhoto = (TextView) findViewById(R.id.isoPhoto);
TextView txtisoPhoto2 = (TextView) findViewById(R.id.isoPhoto2);
TextView txtisoPhoto3 = (TextView) findViewById(R.id.isoPhoto3);
TextView txtlensPhoto = (TextView) findViewById(R.id.lensPhoto);
TextView txtlensPhoto2 = (TextView) findViewById(R.id.lensPhoto2);
TextView txtlensPhoto3 = (TextView) findViewById(R.id.lensPhoto3);
/*txtshutterPhoto.setText(shutterPhoto[0]);
if (shutterPhoto.length > 1) {
txtshutterPhoto2.setText(shutterPhoto[1]);
if (shutterPhoto.length > 2) {
txtshutterPhoto3.setText(shutterPhoto[2]);
}
}
txtisoPhoto.setText(isoPhoto[0]);
if (isoPhoto.length > 1) {
txtisoPhoto2.setText(isoPhoto[1]);
if (isoPhoto.length > 2) {
txtisoPhoto3.setText(isoPhoto[2]);
}
}
txtfilterPhoto.setText(filterPhoto[0]);
if (filterPhoto.length > 1) {
txtfilterPhoto2.setText(filterPhoto[1]);
if ((filterPhoto.length > 2)) {
txtfilterPhoto3.setText(filterPhoto[2]);
}
}
txtaperturePhoto.setText(aperturePhoto[0]);
if (aperturePhoto.length > 1) {
txtaperturePhoto2.setText(aperturePhoto[1]);
if (aperturePhoto.length > 2) {
txtaperturePhoto3.setText(aperturePhoto[2]);
}
}*/
try {
fis = getApplicationContext().openFileInput("bmImg1");
bmImg1 = BitmapFactory.decodeStream(fis);
IMAGES.add(bmImg1);
fis.close();
/*
findViewById(R.id.note1).setVisibility(View.VISIBLE);
TextView descriptionnote = (TextView)findViewById(R.id.note1);
descriptionnote.setText(descriptionPhoto[0]);
*/
if(numpics>1){
fis2 = getApplicationContext().openFileInput("bmImg2");
bmImg2 = BitmapFactory.decodeStream(fis2);
IMAGES.add(bmImg2);
fis2.close();
/*
findViewById(R.id.note1).setVisibility(View.INVISIBLE);
findViewById(R.id.note2).setVisibility(View.VISIBLE);
TextView descriptionnote2 = (TextView)findViewById(R.id.note2);
descriptionnote2.setText(descriptionPhoto[1]);
*/
if(numpics>2){
fis3 = getApplicationContext().openFileInput("bmImg3");
bmImg3 = BitmapFactory.decodeStream(fis3);
IMAGES.add(bmImg3);
fis3.close();
/*
findViewById(R.id.note2).setVisibility(View.INVISIBLE);
findViewById(R.id.note3).setVisibility(View.VISIBLE);
TextView descriptionnote3 = (TextView)findViewById(R.id.note3);
descriptionnote3.setText(descriptionPhoto[2]);
*/
}
}
}
catch (FileNotFoundException e) {
Log.d(TAG, "file not found");
e.printStackTrace();
}
catch (IOException e) {
Log.d(TAG, "io exception");
e.printStackTrace();
}
PagerAdapter pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
page = (ViewPager)findViewById(R.id.pager);
page.setAdapter(pagerAdapter);
page.setCurrentItem(position_pic);
if(page.getCurrentItem()==0 ){
findViewById(R.id.note1).setVisibility(View.VISIBLE);
findViewById(R.id.note2).setVisibility(View.INVISIBLE);
findViewById(R.id.note3).setVisibility(View.INVISIBLE);
TextView descriptionnote = (TextView) findViewById(R.id.note1);
descriptionnote.setText(descriptionPhoto[0]);
}
if (page.getCurrentItem()==1 ) {
findViewById(R.id.note1).setVisibility(View.INVISIBLE);
findViewById(R.id.note2).setVisibility(View.VISIBLE);
findViewById(R.id.note3).setVisibility(View.INVISIBLE);
TextView descriptionnote2 = (TextView) findViewById(R.id.note2);
descriptionnote2.setText(descriptionPhoto[1]);
}
if (page.getCurrentItem()==2 ) {
findViewById(R.id.note1).setVisibility(View.INVISIBLE);
findViewById(R.id.note2).setVisibility(View.INVISIBLE);
findViewById(R.id.note3).setVisibility(View.VISIBLE);
TextView descriptionnote3 = (TextView) findViewById(R.id.note3);
descriptionnote3.setText(descriptionPhoto[2]);
}
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
finish();
return true;
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
public int getItemPosition(Object item){
return POSITION_NONE;
}
#Override
public Fragment getItem(int position) {
ViewPagerFragment fragment = new ViewPagerFragment();
fragment.setAsset(IMAGES.get(position));
return fragment;
}
#Override
public int getCount() {
return IMAGES.size();
}
}}
This is the ViewPagerFragment
public class ViewPagerFragment extends Fragment {
private static final String BUNDLE_ASSET = "res";
private Bitmap asset;
public ViewPagerFragment() {
}
public void setAsset(Bitmap asset) {
this.asset = asset;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.view_pager_page, container, false);
/* if (savedInstanceState != null) {
if (asset == null && savedInstanceState.containsKey(BUNDLE_ASSET)) {
asset = savedInstanceState.getParcelable(BUNDLE_ASSET);
}
}*/
if (asset != null) {
SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)rootView.findViewById(R.id.imageView);
imageView.setImage(ImageSource.bitmap(asset));
}
return rootView;
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
View rootView = getView();
if (rootView != null) {
outState.putString(BUNDLE_ASSET, String.valueOf(asset));
}
}}
ViewPager.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#333">
<GridLayout
android:id="#+id/suggestedParameter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="visible"
android:paddingTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_below="#+id/textParameter"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:id="#+id/shot_levellabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/shot_levellabel"
android:layout_weight="0.10"
android:gravity="center"
android:layout_row="0"
android:layout_column="0"
android:textColor="#ffffff" />
<TextView
android:id="#+id/shot_levelsuggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="0"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/shot_levelPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="2"
android:layout_column="0"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="#+id/shot_levelPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="3"
android:layout_column="0" />
<TextView
android:id="#+id/shot_levelPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="4"
android:layout_column="0" />-->
<TextView
android:id="#+id/shutterPhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/shutterPhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="1"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/shutter_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="1"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/shutterPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="2"
android:layout_column="1"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="#+id/shutterPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="3"
android:layout_column="1" />
<TextView
android:id="#+id/shutterPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="4"
android:layout_column="1" />-->
<TextView
android:id="#+id/aperturePhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/aperturePhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="2"
android:textColor="#ffffff" />
<TextView
android:id="#+id/aperture_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="2"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/aperturePhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="2"
android:layout_column="2"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="#+id/aperturePhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="3"
android:layout_column="2" />
<TextView
android:id="#+id/aperturePhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="4"
android:layout_column="2" />-->
<TextView
android:id="#+id/isoPhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/isoPhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="3"
android:textColor="#ffffff" />
<TextView
android:id="#+id/iso_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="3"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/isoPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center|right"
android:layout_weight="0.10"
android:paddingRight="10dp"
android:layout_row="2"
android:layout_column="3"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="#+id/isoPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center|right"
android:layout_weight="0.10"
android:paddingRight="10dp"
android:layout_row="3"
android:layout_column="3" />
<TextView
android:id="#+id/isoPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center|right"
android:layout_weight="0.10"
android:paddingRight="10dp"
android:layout_row="4"
android:layout_column="3" />-->
<TextView
android:id="#+id/lensPhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lensPhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="4"
android:textColor="#ffffff" />
<TextView
android:id="#+id/lens_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center|left"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="4"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/lensPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="2"
android:layout_column="4"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="#+id/lensPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="3"
android:layout_column="4"
/>
<TextView
android:id="#+id/lensPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="4"
android:layout_column="4"
/>-->
<TextView
android:id="#+id/filterPhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/filterPhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="5"
android:textColor="#ffffff" />
<TextView
android:id="#+id/filter_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_row="1"
android:layout_column="5"
android:textColorHint="#ffffff" />
<TextView
android:id="#+id/filterPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_row="2"
android:layout_column="5"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="#+id/filterPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_row="3"
android:layout_column="5"
/>
<TextView
android:id="#+id/filterPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_row="4"
android:layout_column="5"
/>-->
</GridLayout>
<!--<TextView
android:id="#+id/parameter_suggested"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="visible"
/>
<TextView
android:id="#+id/parameter2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="invisible"
android:text="456"
android:layout_below="#+id/parameter_suggested"
/>
<TextView
android:id="#+id/parameter3"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="visible"
android:text="789"
android:layout_below="#+id/parameter_suggested"
/>
-->
</RelativeLayout>
<RelativeLayout
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#333">
<TextView
android:id="#+id/note1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="invisible"
/>
<TextView
android:id="#+id/note2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="invisible"
/>
<TextView
android:id="#+id/note3"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="invisible"
/>
</RelativeLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_above="#id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/text1" />
</RelativeLayout>

you should add image into Map or Array For Reloading:
#Override
public void fill(final Picture picture, int pos, Object... objects) {
image=(ImageView) view.findViewById(R.id.img_galleryadapter_image);
caption=(TextView) view.findViewById(R.id.txt_galleryadapter_caption);
if(bitmapMap.containsKey(picture.imageUrl)){
image.setImageBitmap(bitmapMap.get(picture.imageUrl));
}else {
image.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_hourglass_empty_black_48dp));
Picasso.with(context).load(picture.imageUrl).memoryPolicy(MemoryPolicy.NO_CACHE).skipMemoryCache().into(new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
image.setImageBitmap(bitmap);
bitmapMap.put(picture.imageUrl, bitmap);
}
#Override
public void onBitmapFailed(Drawable drawable) {}
#Override
public void onPrepareLoad(Drawable drawable) {}
});
}
caption.setText(picture.caption);
}
add to a map:
public static Map<String,Bitmap> bitmapMap=new LinkedHashMap<>();

edit your layout in the xml file to put image then below it a textview using RelativeLayoutor once ur image and its description is aligned its upto ur java codes

After struggling and reading so many different solutions I fixed by myself the issue.
I wanted share with you my solutions maybe can help someone else.
Feel free to ask me everything about it.
This is the FragmentActivity:
public class ViewPagerActivity extends FragmentActivity {
private boolean again=false;
private ViewPager page;
private Bitmap bmImg1;
private Bitmap bmImg2;
private Bitmap bmImg3;
private String TAG;
ArrayList<Bitmap> IMAGES =new ArrayList<>();
ArrayList<String> DESCRIPTIONS =new ArrayList<>();
ArrayList<String> SHOTLEVEL=new ArrayList<>();
ArrayList<String> FILTERPHOTO=new ArrayList<>();
ArrayList<String> APERTUREPHOTO=new ArrayList<>();
ArrayList<String> SHUTTERPHOTO=new ArrayList<>();
ArrayList<String> ISOPHOTO=new ArrayList<>();
ArrayList<String> LENSPHOTO=new ArrayList<>();
String[] descriptionPhoto;
private String shot_levelPhoto;
private String shot_levelPhoto1;
private String shot_levelPhoto2;
private String filterPhoto;
private String filterPhoto1;
private String filterPhoto2;
private String aperturePhoto;
private String aperturePhoto1;
private String aperturePhoto2;
private String shutterPhoto;
private String shutterPhoto1;
private String shutterPhoto2;
private String isoPhoto;
private String isoPhoto1;
private String isoPhoto2;
private String focal_lengthPhoto;
private String focal_lengthPhoto1;
private String focal_lengthPhoto2;
private String[] shot_levelPhotoArray= new String[3];
private String[] filterPhotoArray= new String[3];
private String[] aperturePhotoArray=new String[3];
private String[] shutterPhotoArray=new String[3];
private String[] isoPhotoArray=new String[3];
private String[] focal_lengthPhotoArray=new String[3];
int numpics=1;
private int position_pic;
private String suggested_aperture;
private String suggested_filter;
private String suggested_iso;
private String suggested_shutter;
private String suggested_shot_level;
private String suggested_lens;
private LayoutInflater inflater;
private boolean firsttime;
private boolean secondtime;
private int oldposition=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_pager);
FileInputStream fis;
FileInputStream fis2;
FileInputStream fis3;
Bundle intent=getIntent().getExtras();
descriptionPhoto = intent.getStringArray("descriptionPhoto");
numpics = (int) intent.get("numpics");
position_pic = (int) intent.get("position_pic");
suggested_aperture= intent.getString("suggested_aperture");
suggested_filter= intent.getString("suggested_filter");
suggested_iso= intent.getString("suggested_iso");
suggested_shutter= intent.getString("suggested_shutter");
suggested_shot_level= intent.getString("suggested_shot_level");
suggested_lens= intent.getString("suggested_lens");
shot_levelPhoto=intent.getString("shot_levelPhoto");
shot_levelPhoto1=intent.getString("shot_levelPhoto1");
shot_levelPhoto2=intent.getString("shot_levelPhoto2");
shot_levelPhotoArray[0] = shot_levelPhoto;
if(!shot_levelPhoto1.equals("null")){
shot_levelPhotoArray[1]=shot_levelPhoto1;
if(!shot_levelPhoto2.equals("null")){
shot_levelPhotoArray[2]=shot_levelPhoto2;
}
}
filterPhoto =intent.getString("filterPhoto");
filterPhoto1 =intent.getString("filterPhoto1");
filterPhoto2 =intent.getString("filterPhoto2");
filterPhotoArray[0]= filterPhoto;
if(!filterPhoto1.equals("null")){
filterPhotoArray[1]=filterPhoto1;
if(!filterPhoto2.equals("null")){
filterPhotoArray[2]=filterPhoto2;
}
}
aperturePhoto =intent.getString("aperturePhoto");
aperturePhoto1 =intent.getString("aperturePhoto1");
aperturePhoto2 =intent.getString("aperturePhoto2");
aperturePhotoArray[0]= aperturePhoto;
if(!aperturePhoto1.equals("null")){
aperturePhotoArray[1]=aperturePhoto1;
if(!aperturePhoto2.equals("null")){
aperturePhotoArray[2]=aperturePhoto2;
}
}
shutterPhoto =intent.getString("shutterPhoto");
shutterPhoto1 =intent.getString("shutterPhoto1");
shutterPhoto2 =intent.getString("shutterPhoto2");
shutterPhotoArray[0]= shutterPhoto;
if(!shutterPhoto1.equals("null")){
shutterPhotoArray[1]=shutterPhoto1;
if(!shutterPhoto2.equals("null")){
shutterPhotoArray[2]=shutterPhoto2;
}
}
isoPhoto =intent.getString("isoPhoto");
isoPhoto1 =intent.getString("isoPhoto1");
isoPhoto2 =intent.getString("isoPhoto2");
isoPhotoArray[0]= isoPhoto;
if(!isoPhoto1.equals("null")){
isoPhotoArray[1]=isoPhoto1;
if(!isoPhoto2.equals("null")){
isoPhotoArray[2]=isoPhoto2;
}
}
focal_lengthPhoto=intent.getString("focal_lengthPhoto");
focal_lengthPhoto1=intent.getString("focal_lengthPhoto1");
focal_lengthPhoto2=intent.getString("focal_lengthPhoto2");
focal_lengthPhotoArray[0]= focal_lengthPhoto;
if(!focal_lengthPhoto1.equals("null")){
focal_lengthPhotoArray[1]=focal_lengthPhoto1;
if(!focal_lengthPhoto2.equals("null")){
focal_lengthPhotoArray[2]=focal_lengthPhoto2;
}
}
TextView txtaperture_suggested = (TextView) findViewById(R.id.aperture_suggested);
TextView txtfilter_suggested = (TextView) findViewById(R.id.filter_suggested);
TextView txtiso_suggested = (TextView) findViewById(R.id.iso_suggested);
TextView txtlens_suggested = (TextView) findViewById(R.id.lens_suggested);
TextView txtshutter_suggested = (TextView) findViewById(R.id.shutter_suggested);
TextView txtshot_levelsuggested = (TextView) findViewById(R.id.shot_levelsuggested);
if (suggested_shot_level == "1") {
txtshot_levelsuggested.setText("Easy");
} else if (suggested_shot_level =="2") {
txtshot_levelsuggested.setText("Medium");
} else if (suggested_shot_level =="3") {
txtshot_levelsuggested.setText("Difficult");
} else if (suggested_shot_level =="4"){
txtshot_levelsuggested.setText("Pro");
}
txtaperture_suggested.setText(suggested_aperture);
txtfilter_suggested.setText(suggested_filter);
txtiso_suggested.setText(suggested_iso);
txtshutter_suggested.setText(suggested_shutter);
txtlens_suggested.setText(suggested_lens);
/* TextView txtshutterPhoto = (TextView) findViewById(R.id.shutterPhoto);
TextView txtshutterPhoto2 = (TextView) findViewById(R.id.shutterPhoto2);
TextView txtshutterPhoto3 = (TextView) findViewById(R.id.shutterPhoto3);
TextView txtshot_levelPhoto = (TextView) findViewById(R.id.shot_levelPhoto);
TextView txtshot_levelPhoto2 = (TextView) findViewById(R.id.shot_levelPhoto2);
TextView txtshot_levelPhoto3 = (TextView) findViewById(R.id.shot_levelPhoto3);
TextView txtaperturePhoto = (TextView) findViewById(R.id.aperturePhoto);
TextView txtaperturePhoto2 = (TextView) findViewById(R.id.aperturePhoto2);
TextView txtaperturePhoto3 = (TextView) findViewById(R.id.aperturePhoto3);
TextView txtfilterPhoto = (TextView) findViewById(R.id.filterPhoto);
TextView txtfilterPhoto2 = (TextView) findViewById(R.id.filterPhoto2);
TextView txtfilterPhoto3 = (TextView) findViewById(R.id.filterPhoto3);
TextView txtisoPhoto = (TextView) findViewById(R.id.isoPhoto);
TextView txtisoPhoto2 = (TextView) findViewById(R.id.isoPhoto2);
TextView txtisoPhoto3 = (TextView) findViewById(R.id.isoPhoto3);
TextView txtfocal_lengthPhoto = (TextView) findViewById(R.id.lensPhoto);
TextView txtfocal_lengthPhoto2 = (TextView) findViewById(R.id.lensPhoto2);
TextView txtfocal_lengthPhoto3 = (TextView) findViewById(R.id.lensPhoto3);*/
/* if (shot_levelPhotoArray[0] == "1") {
txtshot_levelPhoto.setText("Easy");
shot_levelPhotoArray[0] = "Easy";
*//*txtshot_levelPhoto2.setText("Easy");
txtshot_levelPhoto3.setText("Easy");*//*
} else if (shot_levelPhotoArray[0] == "2") {
txtshot_levelPhoto.setText("Medium");
shot_levelPhotoArray[0] = "Medium";
*//* txtshot_levelPhoto2.setText("Medium");
txtshot_levelPhoto3.setText("Medium");*//*
} else if (shot_levelPhotoArray[0] == "3") {
txtshot_levelPhoto.setText("Difficult");
shot_levelPhotoArray[0] = "Difficult";
*//*txtshot_levelPhoto2.setText("Difficult");
txtshot_levelPhoto3.setText("Difficult");*//*
} else {
txtshot_levelPhoto.setText("Pro");
shot_levelPhotoArray[0] = "Pro";
*//* txtshot_levelPhoto2.setText("Pro");
txtshot_levelPhoto3.setText("Pro");*//*
}
txtshutterPhoto.setText(shutterPhoto);
txtisoPhoto.setText(isoPhoto);
txtfilterPhoto.setText(filterPhoto);
txtaperturePhoto.setText(aperturePhoto);
txtfocal_lengthPhoto.setText(focal_lengthPhoto);*/
/*txtshutterPhoto.setText(shutterPhoto[0]);
if (shutterPhoto.length > 1) {
txtshutterPhoto2.setText(shutterPhoto[1]);
if (shutterPhoto.length > 2) {
txtshutterPhoto3.setText(shutterPhoto[2]);
}
}
txtisoPhoto.setText(isoPhoto[0]);
if (isoPhoto.length > 1) {
txtisoPhoto2.setText(isoPhoto[1]);
if (isoPhoto.length > 2) {
txtisoPhoto3.setText(isoPhoto[2]);
}
}
txtfilterPhoto.setText(filterPhoto[0]);
if (filterPhoto.length > 1) {
txtfilterPhoto2.setText(filterPhoto[1]);
if ((filterPhoto.length > 2)) {
txtfilterPhoto3.setText(filterPhoto[2]);
}
}
txtaperturePhoto.setText(aperturePhoto[0]);
if (aperturePhoto.length > 1) {
txtaperturePhoto2.setText(aperturePhoto[1]);
if (aperturePhoto.length > 2) {
txtaperturePhoto3.setText(aperturePhoto[2]);
}
}*/
try {
fis = getApplicationContext().openFileInput("bmImg1");
bmImg1 = BitmapFactory.decodeStream(fis);
IMAGES.add(bmImg1);
DESCRIPTIONS.add(descriptionPhoto[0]);
SHOTLEVEL.add(shot_levelPhotoArray[0]);
FILTERPHOTO.add(filterPhotoArray[0]);
APERTUREPHOTO.add(aperturePhotoArray[0]);
SHUTTERPHOTO.add(shutterPhotoArray[0]);
ISOPHOTO.add(isoPhotoArray[0]);
LENSPHOTO.add(focal_lengthPhotoArray[0]);
fis.close();
if(numpics>1){
fis2 = getApplicationContext().openFileInput("bmImg2");
bmImg2 = BitmapFactory.decodeStream(fis2);
IMAGES.add(bmImg2);
DESCRIPTIONS.add(descriptionPhoto[1]);
SHOTLEVEL.add(shot_levelPhotoArray[1]);
FILTERPHOTO.add(filterPhotoArray[1]);
APERTUREPHOTO.add(aperturePhotoArray[1]);
SHUTTERPHOTO.add(shutterPhotoArray[1]);
ISOPHOTO.add(isoPhotoArray[1]);
LENSPHOTO.add(focal_lengthPhotoArray[1]);
fis2.close();
if(numpics>2){
fis3 = getApplicationContext().openFileInput("bmImg3");
bmImg3 = BitmapFactory.decodeStream(fis3);
IMAGES.add(bmImg3);
DESCRIPTIONS.add(descriptionPhoto[2]);
SHOTLEVEL.add(shot_levelPhotoArray[2]);
FILTERPHOTO.add(filterPhotoArray[2]);
APERTUREPHOTO.add(aperturePhotoArray[2]);
SHUTTERPHOTO.add(shutterPhotoArray[2]);
ISOPHOTO.add(isoPhotoArray[2]);
LENSPHOTO.add(focal_lengthPhotoArray[2]);
fis3.close();
}
}
}
catch (FileNotFoundException e) {
Log.d(TAG, "file not found");
e.printStackTrace();
}
catch (IOException e) {
Log.d(TAG, "io exception");
e.printStackTrace();
}
PagerAdapter pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager(), descriptionPhoto[position_pic]);
page = (ViewPager)findViewById(R.id.pager);
page.setAdapter(pagerAdapter);
page.setCurrentItem(position_pic);
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
public void clear() {
IMAGES.clear();
DESCRIPTIONS.clear();
SHOTLEVEL.clear();
FILTERPHOTO.clear();
APERTUREPHOTO.clear();
SHUTTERPHOTO.clear();
ISOPHOTO.clear();
LENSPHOTO.clear();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
finish();
return true;
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
String description;
public ScreenSlidePagerAdapter(FragmentManager fm, String description) {
super(fm);
this.description=description;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
}
//this is called when notifyDataSetChanged() is called
#Override
public int getItemPosition(Object object) {
// refresh all fragments when data set changed
return PagerAdapter.POSITION_NONE;
}
#Override
public boolean isViewFromObject(View view, Object object) {
if(object != null){
return ((Fragment)object).getView() == view;
}else{
return false;
}
}
/*#Override
public Fragment getItem(int position) {
ViewPagerFragment fragment = new ViewPagerFragment();
fragment.setAsset(IMAGES.get(position));
return fragment;
}*/
#Override
public Fragment getItem(int index) {
ViewPagerFragment fragment = new ViewPagerFragment();
//fragment.setAsset(IMAGES.get(index));
fragment.setAsset(IMAGES.get(index), DESCRIPTIONS.get(index));
ViewPagerFragment.newInstance(index,
SHOTLEVEL.get(index),
FILTERPHOTO.get(index),
APERTUREPHOTO.get(index),
SHUTTERPHOTO.get(index),
ISOPHOTO.get(index),
LENSPHOTO.get(index)); // Pages is an array of Strings
return fragment;
}
#Override
public int getCount() {
return IMAGES.size();
}
}
}
This is the Fragment
public class ViewPagerFragment extends Fragment {
private static final String BUNDLE_ASSET = "res";
private Bitmap asset;
String descriptionPhoto;
private TextView tv;
HashMap<Bitmap, String > map;
private static Bundle bundle;
public ViewPagerFragment() {
}
/*public int setAsset(Bitmap asset) {
this.asset = asset;
return 0;
}*/
public HashMap<Bitmap, String> setAsset(Bitmap asset, String description){
map= new HashMap<>();
this.asset = asset;
this.descriptionPhoto=description;
map.put(this.asset, this.descriptionPhoto);
return map;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.view_pager_page, container, false);
if (savedInstanceState != null) {
if (asset == null && savedInstanceState.containsKey(BUNDLE_ASSET)) {
asset = savedInstanceState.getParcelable(BUNDLE_ASSET);
}
}
if (asset != null && descriptionPhoto!=null) {
TextView descriptionnote = (TextView) rootView.findViewById(R.id.note1);
if(descriptionPhoto.equals("null")){
descriptionPhoto="No description for this picture";
}
descriptionnote.setText(descriptionPhoto);
SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)rootView.findViewById(R.id.imageView);
imageView.setImage(ImageSource.bitmap(asset));
TextView txtshot_level = (TextView) rootView.findViewById(R.id.shot_levelPhoto);
TextView txtshutterPhoto = (TextView) rootView.findViewById(R.id.shutterPhoto);
TextView txtaperturePhoto = (TextView) rootView.findViewById(R.id.aperturePhoto);
TextView txtfilterPhoto = (TextView) rootView.findViewById(R.id.filterPhoto);
TextView txtisoPhoto = (TextView) rootView.findViewById(R.id.isoPhoto);
TextView txtfocal_lengthPhoto = (TextView) rootView.findViewById(R.id.lensPhoto);
txtshot_level.setText(bundle.getString("shot_levelcontent"));
txtshutterPhoto.setText(bundle.getString("shuttercontent"));
txtisoPhoto.setText(bundle.getString("isocontent"));
txtfilterPhoto.setText(bundle.getString("filtercontent"));
txtaperturePhoto.setText(bundle.getString("aperturecontent"));
txtfocal_lengthPhoto.setText(bundle.getString("lenscontent"));
}
return rootView;
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
View rootView = getView();
if (rootView != null) {
outState.putString(BUNDLE_ASSET, String.valueOf(asset));
}
}
public static Fragment newInstance(int position,
String shot_level,
String filter,
String aperture,
String shutter,
String iso,
String lens) {
ViewPagerFragment swipeFragment = new ViewPagerFragment();
bundle = new Bundle();
if (shot_level.equals("1")) {
bundle.putString("shot_levelcontent", "Easy");
} else if (shot_level.equals("2")) {
bundle.putString("shot_levelcontent", "Medium");
} else if (shot_level.equals("3")) {
bundle.putString("shot_levelcontent", "Difficult");
} else {
bundle.putString("shot_levelcontent", "Pro");
}
bundle.putString("filtercontent", filter);
bundle.putString("aperturecontent", aperture);
bundle.putString("shuttercontent", shutter);
bundle.putString("isocontent", iso);
bundle.putString("lenscontent", lens);
swipeFragment.setArguments(bundle);
return swipeFragment;
}
}

Related

Modify textview of parent layout from adapter xamarin android

Sorry, I'm using google translate.
Hello, I am developing an application in xamarin android with visual studio 2017 to take requests where I send information from a fragment to a List<EN_WishDetail> to store the selection of items and this is dumped to an adapter to display it in another fragment.
my problem is that the parent layout loads a custom listview where I have 2 buttons to increase and decrease the quantities of the items this works correctly, likewise in the parent layout it has two textviews to count the number of items and the total value of the order , I want that when increasing the amount this also updates the textview of the parent layout from the adapter where the button functions are.
How can I access the parent layout from the adapter and modify its value.
layout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="5">
<TextView
android:text="Cesta de Pedido"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView1"
android:gravity="center"
android:textSize="20dip"
android:textColor="#color/primaryDark" />
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/List" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1"
android:background="#000000">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="#+id/itemItems"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="6dp"
android:text="(0) Items"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="left"
android:layout_weight="3"
android:textColor="#FFFFFF"/>
<Button
android:id="#+id/btnClear"
android:layout_width="50dp"
android:layout_height="40dp"
android:text="Clear"
android:textAppearance="?android:attr/textAppearanceSmall"
android:background="#drawable/Blue_button"
style="#style/button_text"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/itemTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="6dp"
android:text="S/. 0.00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="left"
android:layout_weight="3"
android:textColor="#FFFFFF"/>
<Button
android:id="#+id/btnSave"
android:layout_width="50dp"
android:layout_height="40dp"
android:text="Guardar"
android:textAppearance="?android:attr/textAppearanceSmall"
android:background="#drawable/Blue_button"
style="#style/button_text"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
listview personalized
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<ImageView
android:id="#+id/Image"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignParentLeft="true"
android:layout_marginRight="8dp"
android:src="#drawable/Pedidos"
android:scaleType="fitXY"/>
<TextView
android:id="#+id/Articulo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#id/Image"
android:layout_toRightOf="#id/Image"
android:layout_marginTop="0dip"
android:text="This is Line1"
android:lines="2"
android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/colorTexto"/>
<TextView
android:id="#+id/MonedaU"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_below="#id/Articulo"
android:layout_marginTop="0dip"
android:text="S/."
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_toRightOf="#id/Image"/>
<TextView
android:id="#+id/PrecioU"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/Articulo"
android:layout_marginTop="0dip"
android:text="This is line2"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_toRightOf="#id/MonedaU"
android:singleLine="true"/>
<TextView
android:id="#+id/MonedaT"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_below="#id/Articulo"
android:layout_marginTop="20dip"
android:text="S/."
android:textAppearance="?android:attr/textAppearanceListItem"
android:layout_toRightOf="#id/Image"
android:textStyle="bold"
android:textColor="#color/colorResaltado"/>
<TextView
android:id="#+id/Importe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/Articulo"
android:layout_marginTop="20dip"
android:text="This is line3"
android:textAppearance="?android:attr/textAppearanceListItem"
android:layout_toRightOf="#id/MonedaT"
android:textStyle="bold"
android:textColor="#color/colorResaltado"/>
<Button
android:id="#+id/btnMin"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#id/Articulo"
android:layout_toLeftOf="#+id/Cantidad"
android:text="-"
android:textAppearance="?android:attr/textAppearanceSmall"
android:background="#drawable/red_button"
style="#style/button_text" />
<EditText
android:id="#+id/Cantidad"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btnMax"
android:layout_marginTop="5dip"
android:layout_below="#id/Articulo"
android:textColor="#000000"
android:background="#FFFFFF"
android:text="0"
android:singleLine="true"
android:maxLines="1"
android:inputType="number"
android:gravity="center"
android:textAlignment="center"/>
<Button
android:id="#+id/btnMax"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#id/Articulo"
android:layout_toLeftOf="#+id/btnDel"
android:text="+"
android:textAppearance="?android:attr/textAppearanceSmall"
android:background="#drawable/red_button"
android:layout_gravity="right"
style="#style/button_text" />
<ImageButton
android:id="#+id/btnDel"
android:src="#drawable/Trash_"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#id/Articulo"
android:layout_alignParentRight="true"
style="#style/button_text" />
</RelativeLayout>
Fragment
public class WishFragment : Fragment
{
public WishFragment MyFragment()
{
return this;
}
public WishFragment()
{
RetainInstance = true;
}
private ListView WishlistView;
WishAdapter adapter;
List<EN_WishDetalle> List_Wish = new List<EN_WishDetalle>();
public override View OnCreateView(LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
//HasOptionsMenu = true;
var view = inflater.Inflate(Resource.Layout.Main_Wish, null);
WishlistView = view.FindViewById<ListView>(Resource.Id.List);
EditText txtCantidad = view.FindViewById<EditText>(Resource.Id.Cantidad);
List_Wish = Variables.WishDetalle;
adapter = new WishAdapter(Activity, List_Wish);
WishlistView.Adapter = adapter;
WishlistView = view.FindViewById<ListView>(Resource.Id.List);
Button buttonMax = view.FindViewById<Button>(Resource.Id.btnMax);
Button buttonMin = view.FindViewById<Button>(Resource.Id.btnMin);
ImageButton buttonDel = view.FindViewById<ImageButton>(Resource.Id.btnDel);
TextView txtContador = view.FindViewById<TextView>(Resource.Id.itemItems);
TextView txtTotal = view.FindViewById<TextView>(Resource.Id.itemTotal);
WishlistView.ItemClick += buttonMax_ItemClick;
txtContador.Text ="( " + List_Wish.Count.ToString() + " ) Items";
decimal suma = List_Wish.Sum(item => Convert.ToDecimal(item.importetotal));
txtTotal.Text = "S/. " + suma.ToString("N");
//WishlistView.ItemClick += buttonMin_ItemClick;
//WishlistView.ItemClick += buttonDel_ItemClick;
return view;
}
void buttonMax_ItemClick(object sender,AdapterView.ItemClickEventArgs e)
{
}
void buttonMin_ItemClick(object sender, AdapterView.ItemClickEventArgs x)
{
}
void buttonDel_ItemClick(object sender, AdapterView.ItemClickEventArgs z)
{
}
}
adapter
public class WishAdapter : BaseAdapter<EN_WishDetalle>
{
List<EN_WishDetalle> sList;
Context sContext;
public WishAdapter(Context context, List<EN_WishDetalle> list)
{
sList = list;
sContext = context;
}
public override EN_WishDetalle this[int position]
{
get
{
return sList[position];
}
}
public override int Count
{
get
{
return sList.Count;
}
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = sList[position];
View view = convertView; // re-use an existing view, if one is available
MyViewHolder holder;
if (view != null)
{
holder = view.Tag as MyViewHolder;
holder.buttonDel.Tag = position;
//holder.buttonMax.Tag = position;
//holder.buttonMin.Tag = position;
}
else
{ // otherwise create a new one
holder = new MyViewHolder();
LayoutInflater inflater =
(LayoutInflater)sContext.GetSystemService(Context.LayoutInflaterService);
view = inflater.Inflate(Resource.Layout.item_Wish, null);
holder.txtPrecioU = view.FindViewById<TextView>(Resource.Id.PrecioU);
holder.txtArticulo = view.FindViewById<TextView>(Resource.Id.Articulo);
holder.txtCantidad = view.FindViewById<TextView>(Resource.Id.Cantidad);
holder.txtImporte = view.FindViewById<TextView>(Resource.Id.Importe);
holder.txtMonedaU = view.FindViewById<TextView>(Resource.Id.MonedaU);
holder.txtMonedaT = view.FindViewById<TextView>(Resource.Id.MonedaT);
holder.Art = view.FindViewById<ImageView>(Resource.Id.Image);
holder.buttonMax = view.FindViewById<Button>(Resource.Id.btnMax);
holder.buttonMin = view.FindViewById<Button>(Resource.Id.btnMin);
holder.buttonDel = view.FindViewById<ImageButton>(Resource.Id.btnDel);
holder.buttonMax.Click += delegate
{
sList[position].cantidad = sList[position].cantidad + 1;
sList[position].importetotal = Convert.ToString( sList[position].cantidad * Convert.ToDecimal(item.punitario));
holder.txtCantidad.SetText(Convert.ToString(sList[position].cantidad), TextView.BufferType.Normal);
string format_importe = (sList[position].cantidad * Convert.ToDecimal(item.punitario)).ToString("N");
holder.txtImporte.SetText(format_importe, TextView.BufferType.Normal);
};
holder.buttonMin.Click += delegate
{
if (sList[position].cantidad > 1) {
sList[position].cantidad = sList[position].cantidad - 1;
sList[position].importetotal = Convert.ToString(sList[position].cantidad * Convert.ToDecimal(item.punitario));
holder.txtCantidad.SetText(Convert.ToString(sList[position].cantidad), TextView.BufferType.Normal);
string format_importe = (sList[position].cantidad * Convert.ToDecimal(item.punitario)).ToString("N");
holder.txtImporte.SetText(format_importe, TextView.BufferType.Normal);
}
};
holder.buttonDel.Click += delegate
{ // we get the tag here for buttonDel
int x = (int)holder.buttonDel.Tag;
Android.App.AlertDialog.Builder dialog = new AlertDialog.Builder(sContext);
AlertDialog alert = dialog.Create();
alert.SetTitle("GumisaAPP");
alert.SetMessage("Eliminar item : (" + x.ToString() + ") - " + sList[position].codigo + sList[position].articulo);
alert.SetIcon(Resource.Drawable.Alerta);
alert.SetButton("OK", (c, ev) =>
{
sList.RemoveAt(position);
NotifyDataSetChanged();
});
alert.SetButton2("CANCEL", (c, ev) =>
{
});
alert.Show();
};
holder.buttonDel.Tag = position;
view.Tag = holder;
}
holder.txtPrecioU.Text = Convert.ToDecimal(item.punitario).ToString("N");
holder.txtArticulo.Text = item.articulo;
holder.txtCantidad.Text = item.cantidad.ToString();
holder.txtImporte.Text = Convert.ToDecimal(item.importetotal).ToString("N");
holder.txtMonedaU.Text = item.moneda;
holder.txtMonedaT.Text = item.moneda;
holder.Art.SetImageResource(Android.Resource.Color.Transparent);
if (sList[position].imagenproducto == "")
{
holder.Art.SetImageResource(Resource.Drawable.NoDisponible);
}
else
{
Android.Net.Uri myUri = (Android.Net.Uri.Parse(sList[position].imagenproducto));
//Art.SetImageURI(myUri);
holder.Art.SetImageURI(myUri);
}
return view;
}
public class MyViewHolder : Java.Lang.Object
{
public TextView txtPrecioU { get; set; }
public TextView txtArticulo { get; set; }
public TextView txtCantidad { get; set; }
public TextView txtImporte { get; set; }
public TextView txtMonedaU { get; set; }
public TextView txtMonedaT { get; set; }
public ImageView Art { get; set; }
public Button buttonMax { get; set; }
public Button buttonMin { get; set; }
public ImageButton buttonDel { get; set; }
}
}
enter image description here
enter image description here
I hope you can guide me the way to follow, thanks for your time.
Yes, you can use event to achieve this just as ToolmakerSteve mentioned.
I made a simple demo to pass a int parameter to the main page, you can refer to the following code:
1.in your Adapter,define variable MyEvent:
public class WishAdapter : BaseAdapter<EN_WishDetalle>
{
// add EventHandler here
public event EventHandler<int> MyEvent;
//other code
public WishAdapter(Context context, List<EN_WishDetalle> list)
{
sList = list;
sContext = context;
}
//other code
}
2.in method GetView of class WishAdapter , add code for button buttonMax:
holder.buttonMax.Click += delegate
{
// other code
// invoke here
MyEvent?.Invoke(this, 1);
};
3.In WishFragment,do like this:
adapter = new WishAdapter(Activity, List_Wish);
WishlistView.Adapter = adapter;
adapter.MyEvent += Adapter_MyEvent;
And method Adapter_MyEvent is:
private void Adapter_MyEvent(object sender, int e)
{ // here we can get the passed parameter e
Debug.WriteLine("The passed parameter : " + e);
}

Show fragment recyclerViews in Parent Activity

I am simply trying to show a fragments recyclerView inside it's parent activity. The data is there but nothing is showing up. Any thoughts? Here is PagerAdapter, parent and fragment classes with xmls so that all the parts are available to see. I want the RV to fit right here between the CardView and comment line. Thanks for any help!
PagerAdapter
public class DropPagerAdapter extends FragmentPagerAdapter{
final int PAGE_COUNT = 2;
private String tabTitles[] = new String[] { "Comments", "Riples"};
private Context context;
public DropPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
}
#Override
public int getCount() {
return PAGE_COUNT;
}
#Override
public Fragment getItem(int position) {
return CommentFragment.newInstance(position + 1);
}
#Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
return tabTitles[position];
}
}
Fragment.java
public class CommentFragment extends Fragment {
public static final String ARG_PAGE = "ARG_PAGE";
private int mPage;
private String mDropObjectId;
private String mAuthorId;
private String mAuthorRank;
private String mAuthorName;
private String mAuthorFacebookId;
private String mDropDescription;
private String mRipleCount;
private String mCommentCount;
private Date mCreatedAt;
private String mTabName;
private RecyclerView mRecyclerView;
private TextView mViewDropEmptyView;
private ArrayList<CommentItem> mCommentList;
private CommentAdapter mCommentAdapter;
public static CommentFragment newInstance(int page) {
Bundle args = new Bundle();
args.putInt(ARG_PAGE, page);
CommentFragment fragment = new CommentFragment();
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPage = getArguments().getInt(ARG_PAGE);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_comment, container, false);
mRecyclerView = (RecyclerView) view.findViewById(R.id.comment_recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mViewDropEmptyView = (TextView) view.findViewById(R.id.comment_empty_view);
Intent intent = getActivity().getIntent();
mDropObjectId = intent.getStringExtra("dropObjectId");
mAuthorId = intent.getStringExtra("authorId");
mAuthorRank = intent.getStringExtra("authorRank");
mAuthorName = intent.getStringExtra("commenterName");
mAuthorFacebookId = intent.getStringExtra("authorFacebookId");
mDropDescription = intent.getStringExtra("dropDescription");
mRipleCount = intent.getStringExtra("ripleCount");
mCommentCount = intent.getStringExtra("commentCount");
mCreatedAt = (Date) intent.getSerializableExtra("createdAt");
mTabName = intent.getStringExtra("mTabName");
loadCommentsFromParse();
return view;
}
public void loadCommentsFromParse() {
final ArrayList<CommentItem> commentList = new ArrayList<>();
final ParseQuery<ParseObject> query = ParseQuery.getQuery("Comments");
query.whereEqualTo("dropId", mDropObjectId);
query.orderByDescending("createdAt");
query.include("commenterPointer");
// query.setLimit(25);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if (e != null) {
Log.d("KEVIN", "error error");
} else {
for (int i = 0; i < list.size(); i++) {
final CommentItem commentItem = new CommentItem();
ParseObject commenterData = (ParseObject) list.get(i).get("commenterPointer");
//Commenter data////////////////////////////////////////////////////////////
ParseFile profilePicture = (ParseFile) commenterData.get("parseProfilePicture");
if (profilePicture != null) {
profilePicture.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
// Bitmap resized = Bitmap.createScaledBitmap(bmp, 100, 100, true);
commentItem.setParseProfilePicture(bmp);
updateRecyclerView(commentList);
}
}
});
}
//CommenterId
commentItem.setCommenterId(commenterData.getObjectId());
//Commenter Name
commentItem.setCommenterName((String) commenterData.get("displayName"));
//Rank
commentItem.setCommenterRank((String) commenterData.get("userRank"));
//Comment Data/////////////////////////////////////////////////////////////
// DropId
commentItem.setDropId(list.get(i).getString("dropId"));
//Comment
commentItem.setCommentText(list.get(i).getString("commentText"));
//Date
commentItem.setCreatedAt(list.get(i).getCreatedAt());
commentList.add(commentItem);
}
Log.i("KEVIN", "Comment list size: " + commentList.size());
}
}
});
}
private void updateRecyclerView(ArrayList<CommentItem> comments) {
if (comments.isEmpty()) {
mRecyclerView.setVisibility(View.GONE);
mViewDropEmptyView.setVisibility(View.VISIBLE);
}
else {
mRecyclerView.setVisibility(View.VISIBLE);
mViewDropEmptyView.setVisibility(View.GONE);
}
mCommentAdapter = new CommentAdapter(getActivity(), comments);
ScaleInAnimationAdapter scaleAdapter = new ScaleInAnimationAdapter(mCommentAdapter);
mRecyclerView.setAdapter(new AlphaInAnimationAdapter(scaleAdapter));
mRecyclerView.setAdapter(mCommentAdapter);
}
}
Fragment XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/comment_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/Primary_Background_Color"
/>
<TextView
android:id="#+id/comment_empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom|center_horizontal"
android:visibility="visible"
android:text="Post a comment on this Drop!"
android:textSize="18sp"
android:textStyle="italic"
android:foregroundGravity="center"
android:paddingBottom="200dp"
android:textAlignment="center"/>
Parent XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:background="#color/Primary_Background_Color"
android:orientation="vertical"
android:weightSum="1">
<android.support.v7.widget.CardView
android:id="#+id/card_view_drop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="true"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#FFFFFF"
card_view:cardPreventCornerOverlap="false"
>
<android.support.design.widget.TabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
android:layout_gravity="bottom"/>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="#android:color/white"/>
<RelativeLayout
android:id="#+id/click_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:background="#drawable/custom_bg">
<android.support.v7.widget.Toolbar
android:id="#+id/trickle_card_tool_bar"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#BBDEFB"
/>
<ImageView
android:id="#+id/profile_picture"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_user_default"
android:background="#drawable/custom_bg"/>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/profile_picture"
android:width="50dp"
android:text="Kevin Hodges"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp"
android:textColor="#000000"
android:singleLine="true"
android:layout_alignTop="#+id/profile_picture"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_toStartOf="#+id/menu_button"
android:layout_toLeftOf="#+id/menu_button"
android:background="#drawable/custom_bg_blue"
android:clickable="true"
android:textStyle="bold"/>
<TextView
android:id="#+id/comment_created_at"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="September 18, 2015 # 3:32 p.m."
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="10sp"
android:singleLine="true"
android:background="#drawable/custom_bg"
android:gravity="left"
android:layout_alignBottom="#+id/profile_picture"
android:layout_alignRight="#+id/menu_button"
android:layout_alignEnd="#+id/menu_button"
android:layout_toRightOf="#+id/profile_picture"
android:layout_marginLeft="8dp"
/>
<TextView
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:enabled="true"
android:focusable="false"
android:maxLines="5"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:singleLine="false"
android:text="Description"
android:layout_below="#+id/profile_picture"
android:textColor="#color/PrimaryText"
android:textSize="14sp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="32dp"
android:background="#drawable/custom_bg"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/menu_button"
android:layout_marginLeft="8dp"
android:src="#drawable/menu_svg"
android:layout_alignBottom="#+id/trickle_card_tool_bar"
android:layout_marginBottom="16dp"
android:background="#drawable/custom_bg_blue"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginRight="2dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""Mother Teresa""
android:id="#+id/author_rank"
android:textSize="14sp"
android:singleLine="false"
android:gravity="left|center_vertical|center_horizontal"
android:layout_alignLeft="#+id/name"
android:layout_alignStart="#+id/name"
android:textStyle="italic"
android:layout_below="#+id/name"
android:layout_alignBottom="#+id/trickle_card_tool_bar"
android:textColor="#7d000000"
android:layout_toStartOf="#+id/menu_button"
android:layout_marginTop="-4dp"
android:layout_toLeftOf="#+id/menu_button"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<AutoCompleteTextView
android:id="#+id/enter_comment_text"
android:layout_width="235dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignTop="#+id/button_post_comment"
android:layout_toLeftOf="#+id/button_post_comment"
android:layout_toRightOf="#+id/post_comment_profile_picture"
android:layout_toStartOf="#+id/button_post_comment"
android:background="#ffffff"
android:hint="#string/write_comment_hint"
android:inputType="textCapSentences|textAutoComplete|textAutoCorrect|text"
android:maxLength="250"
android:paddingLeft="8dp"/>
<ImageView
android:id="#+id/post_comment_profile_picture"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:foregroundGravity="center_vertical"
android:scaleType="centerCrop"
android:src="#drawable/ic_user_default"/>
<Button
android:id="#+id/button_post_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:width="50dp"
android:background="#color/AccentColor"
android:text="Post"
android:textColor="#ffffff"/>

Listview not displaying below RelativeLayout

ListView is not showing, any assistance is greatly appreciated! I am able to display products with ListView alone but I cannot figure out how to display it below my Relative Layout.
Cart.java:
public class Cart extends AppCompatActivity {
private String user;
static CartChangeListener cartChangeListener;
ProductsAdapter adaptCart;
ArrayList<Product> cartItems = new ArrayList<>();
Menu menu;
float total = (float)0.00;
float shipCost = 15;
float tax = (float)0.07;
String URI;
TextView subTotal;
TextView shipping;
TextView taxes;
TextView totals;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cart);
View header = getLayoutInflater().inflate(R.layout.activity_cart, null);
//ListView.addHeaderView(headerView);
user = MainActivity.currentAccount.getUsername();
if(user == null || user.equals("Guest")) {
shipCost = (float)0.00;
tax = (float)0.00;
}
if(user != null && !(user.equals("Guest"))) {
new getCartIcon().execute();
//View header = getLayoutInflater().inflate(R.layout.activity_cart, null);
//View footer = getLayoutInflater().inflate(R.layout.activity_search, null);
ListView listView = (ListView) findViewById(R.id.list_cart_view);
new returnCartItems().execute();
//if (!(cartItems.isEmpty())) {
adaptCart = new ProductsAdapter(Cart.this, 0, cartItems);
listView.setOnItemClickListener(new ListView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
try {
ProductsAdapter.ViewHolder holder = new ProductsAdapter.ViewHolder();
holder.product_name = (TextView) v.findViewById(R.id.product_name);
holder.product_dept = (TextView) v.findViewById(R.id.product_dept);
holder.product_desc = (TextView) v.findViewById(R.id.product_desc);
holder.product_price = (TextView) v.findViewById(R.id.product_price);
holder.product_qty = (TextView) v.findViewById(R.id.product_qty);
holder.product_img = (ImageView) findViewById(R.id.icon);
URI = "http://www.michaelscray.com/Softwear/graphics/";
String dept = "Dept: ";
String money = "$";
String qty = "Qty: ";
URI += cartItems.get(position).getProduct_img();
Uri uris = Uri.parse(URI + cartItems.get(position).getProduct_img());
URI uri = java.net.URI.create(URI);
holder.product_name.setText(cartItems.get(position).getProduct_name());
holder.product_desc.setText(cartItems.get(position).getProduct_desc());
holder.product_dept.setText(dept + cartItems.get(position).getProduct_dept());
holder.product_price.setText(money + String.valueOf(cartItems.get(position).getPrice()));
holder.product_qty.setText(qty + String.valueOf(cartItems.get(position).getProduct_qty()));
Picasso.with(getApplicationContext()).load(URI).error(R.mipmap.ic_launcher).into(holder.product_img);
} catch (Exception e) {
e.printStackTrace();
}
}
});
listView.setAdapter(adaptCart);
//}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu_main, menu);
this.menu = menu;
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
return true;
}
public class getCartIcon extends AsyncTask<Void, Void, Void> {
String tempUser = user;
int cartNum = 0;
float tempTotal;
#Override
protected void onPreExecute() {
subTotal = (TextView) findViewById(R.id.textView_subTotal);
shipping = (TextView) findViewById(R.id.textView_shipping);
totals = (TextView) findViewById(R.id.textView_total);
taxes = (TextView) findViewById(R.id.textView_taxes);
}
#Override
protected Void doInBackground(Void... arg0) {
if(tempUser != null) {
try {
Connection conn = ConnectDB.getConnection();
String queryString = "SELECT * FROM Orders WHERE `User_Name` = '" + tempUser + "'";
PreparedStatement st = conn.prepareStatement(queryString);
//st.setString(1, tempUser);
final ResultSet result = st.executeQuery(queryString);
while (result.next()) {
try {
tempTotal += result.getFloat("Price");
//skus.add(result.getInt("SKU"));
} catch(SQLException e) {
e.printStackTrace();
}
cartNum++;
//setTotal(result.getFloat(String.valueOf("Price")));
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
protected void onPostExecute(Void result) {
getCartItems(cartNum);
subTotal.setText(String.valueOf(tempTotal));
shipping.setText(String.valueOf(shipCost));
tax = tempTotal * tax;
taxes.setText(String.valueOf(tax));
totals.setText(String.valueOf(tempTotal + shipCost + tax));
//setTotal(tempTotal);
//super.onPostExecute(result);
}
}
public class returnCartItems extends AsyncTask<Void, Void, Void> {
String tempUser = user;
Product product = null;
List<Integer> skus = new ArrayList<>();
//String descr = "DETAILS: \n\n";
#Override
protected void onPreExecute() {
}
#Override
protected Void doInBackground(Void... arg0) {
if(tempUser != null) {
try {
Connection conn = ConnectDB.getConnection();
String queryString = "SELECT * FROM Orders WHERE `User_Name` = '" + tempUser + "'";
PreparedStatement st = conn.prepareStatement(queryString);
//st.setString(1, tempUser);
final ResultSet result = st.executeQuery(queryString);
while (result.next()) {
try {
skus.add(result.getInt("SKU"));
} catch(SQLException e) {
e.printStackTrace();
}
}
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
Connection conn = ConnectDB.getConnection();
String queryString = "SELECT * FROM Inventory";
PreparedStatement st = conn.prepareStatement(queryString);
//st.setString(1, tempUser);
final ResultSet result = st.executeQuery(queryString);
while (result.next()) {
for(int i=0; i < skus.size(); i++) {
if(skus.get(i) == result.getInt("SKU")) {
product = new Product();
product.setProduct_name(result.getString("Name"));
product.setProduct_dept(result.getString("Department"));
product.setProduct_desc(result.getString("Description"));
product.setPrice(result.getFloat("Price"));
product.setProduct_qty(result.getInt("Quantity"));
product.setProduct_img(result.getString("Image"));
cartItems.add(product);
/*
descr += "Product: " + result.getString("Name") + "\n" +
"Department: " + result.getString("Department") + "\n" +
"Price: $" + result.getFloat("Price") + "\n\n";
*/
}
}
}
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
}
public void setTotal(float total) {
this.total += total;
}
public float getTotal() {
return total;
}
public void getCartItems(int cart) {
MenuItem cartMenuItem = (MenuItem) menu.findItem(R.id.action_cart);
if (cart == 0) {
cartMenuItem.setIcon(R.drawable.cart0);
}
if (cart == 1) {
cartMenuItem.setIcon(R.drawable.cart1);
}
if (cart == 2) {
cartMenuItem.setIcon(R.drawable.cart2);
}
if (cart == 3) {
cartMenuItem.setIcon(R.drawable.cart3);
}
if (cart == 4) {
cartMenuItem.setIcon(R.drawable.cart4);
}
if (cart == 5) {
cartMenuItem.setIcon(R.drawable.cart5);
}
if (cart > 5) {
cartMenuItem.setIcon(R.drawable.cart5plus);
}
if (cart > 10) {
cartMenuItem.setIcon(R.drawable.cart10plus);
}
}
}
ProductsAdapter.java:
public class ProductsAdapter extends ArrayAdapter<Product> {
private Activity activity;
private ArrayList<Product> products;
private static LayoutInflater inflater = null;
String money = "$";
String dept = "Dept: ";
String qty ="Qty: ";
static String URI;
public ProductsAdapter(Activity activity, int textViewResourceId, ArrayList<Product> product) {
super(activity, textViewResourceId, product);
try {
this.activity = activity;
this.products = product;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//imageLoader = new ImageLoader(activity.getApplicationActivity());
} catch (Exception e) {
return;
}
}
#Override
public int getCount() {
return products.size();
}
public Product getItem(Product position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
public static class ViewHolder {
public TextView product_name;
public TextView product_desc;
public TextView product_dept;
public TextView product_price;
public TextView product_qty;
public ImageView product_img;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
final ViewHolder holder;
try {
if(convertView == null) {
vi = inflater.inflate(R.layout.activity_search, parent, false);
holder = new ViewHolder();
holder.product_name = (TextView) vi.findViewById(R.id.product_name);
holder.product_dept = (TextView) vi.findViewById(R.id.product_dept);
holder.product_desc = (TextView) vi.findViewById(R.id.product_desc);
holder.product_price = (TextView) vi.findViewById(R.id.product_price);
holder.product_qty = (TextView) vi.findViewById(R.id.product_qty);
holder.product_img = (ImageView) vi.findViewById(R.id.icon);
vi.setTag(holder);
}
else {
holder = (ViewHolder) vi.getTag();
}
URI = "http://www.michaelscray.com/Softwear/graphics/";
URI += products.get(position).getProduct_img();
Uri uri = Uri.parse(URI + products.get(position).getProduct_img());
holder.product_name.setText(products.get(position).getProduct_name());
holder.product_desc.setText(products.get(position).getProduct_desc());
holder.product_dept.setText(dept + products.get(position).getProduct_dept());
holder.product_price.setText(money + String.valueOf(products.get(position).getPrice()));
holder.product_qty.setText(qty + String.valueOf(products.get(position).getProduct_qty()));
Picasso.with(getContext()).load(URI).error(R.mipmap.ic_launcher).into(holder.product_img);
}
catch(Exception e) {
}
return vi;
}
}
And, activity_cart.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llSliderCart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#5e80ab"
android:orientation="vertical" >
<TextView
android:id="#+id/summary"
android:layout_width="254dp"
android:layout_height="55dp"
android:gravity="center"
android:text="CART SUMMARY"
android:textColor="#ffffff"
android:textSize="18sp"
android:textStyle="bold"
android:layout_alignParentStart="true"
android:layout_toStartOf="#+id/checkout_btn" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Checkout"
android:id="#+id/checkout_btn"
android:background="#drawable/shape"
android:layout_alignParentBottom="false"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="true"
android:paddingLeft="1dp"
android:paddingTop="1dp"
android:paddingRight="1dp"
android:paddingBottom="1dp"
android:textStyle="bold"
android:textColor="#ffffff" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/cart_rows"
android:background="#ffffff"
android:orientation="horizontal" >
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="Subtotal"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/vertical_divider_welcome" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingLeft="20dp"
android:text="#string/currency"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
<TextView
android:id="#+id/textView_subTotal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="0.00"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/vertical_divider_welcome" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/cart_rows"
android:background="#ffffff"
android:orientation="horizontal" >
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="Shipping"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/vertical_divider_welcome" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingLeft="20dp"
android:text="#string/currency"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
<TextView
android:id="#+id/textView_shipping"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="0.00"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/vertical_divider_welcome" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/cart_rows"
android:background="#ffffff"
android:orientation="horizontal" >
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="Tax"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/vertical_divider_welcome" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingLeft="20dp"
android:text="#string/currency"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="0"
android:textColor="#a4a4a4"
android:textSize="#dimen/text_normal"
android:id="#+id/textView_taxes" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/vertical_divider_welcome" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/cart_rows"
android:background="#ffffff"
android:orientation="horizontal" >
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingRight="20dp"
android:text="Total"
android:textStyle="bold"
android:textColor="#color/blue"
android:textSize="#dimen/text_title" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/vertical_divider_welcome" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingLeft="20dp"
android:text="#string/currency"
android:textStyle="bold"
android:textColor="#color/blue"
android:textSize="#dimen/text_title" />
<TextView
android:id="#+id/textView_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:textStyle="bold"
android:paddingRight="20dp"
android:text="0.00"
android:textColor="#color/blue"
android:textSize="#dimen/text_title" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/vertical_divider_welcome" />
<!--
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Description"
android:id="#+id/textView" />
-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cart contents:"
android:id="#+id/contents"
android:background="#color/vertical_divider_welcome"
android:textStyle="bold|italic"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false" />
</RelativeLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:id="#+id/list_cart_view">
</ListView>
</LinearLayout>
Thanks again!
While your RelativeLayout(the one just before the ListView) have match_parent as height, it will take the remaining space of the window... so there is no place for your ListView to be shown.
Try this..
Give id to the above Relative layout and use the same below.
<ListView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_below="#id/"
android:id="#+id/list_cart_view">
</ListView>

ListView in a Popup with EditText Issue in Android

I am having an issue with scrolling of ListView in a Popup. I have an activity that has a dialog theme so that it can open up as a popup. The Popup should contain EditText at the bottom and the remaining area above it should be the ListView. When the activity is started it should start with keypad open & focus on EditText.
Issue: ListView doesn't scroll when keypad is open.
Below is my activity code:
public class CommentsActivity extends Activity{
private InputMethodManager imm;
private String commentCount;
private ShopPirateDatabase db;
private ArrayList<CommentsBean> commentsList = new ArrayList<CommentsBean>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.comments_layout);
imm = (InputMethodManager) this
.getSystemService(Context.INPUT_METHOD_SERVICE);
db=new ShopPirateDatabase(this);
if(getIntent().hasExtra("count")){
commentCount=getIntent().getExtras().getString("count");
}
ListView lvMyComments=(ListView)findViewById(R.id.lvMyComments);
lvMyComments.setVisibility(View.GONE);
final Button btnPost=(Button)findViewById(R.id.btnPost);
btnPost.setVisibility(View.GONE);
etAddComment=(EditText)findViewById(R.id.etAddComment);
RelativeLayout progressLayout=(RelativeLayout)findViewById(R.id.progressLayout);
progressLayout.setVisibility(View.VISIBLE);
TextView tvNoComments=(TextView)findViewById(R.id.tvNoComments);
tvNoComments.setVisibility(View.GONE);
imm.showSoftInput(etAddComment, InputMethodManager.SHOW_IMPLICIT);
if(Integer.parseInt(commentCount) > 0){
getCommentsFromDb();
if(commentsList!=null && commentsList.size() > 0){
progressLayout.setVisibility(View.GONE);
tvNoComments.setVisibility(View.GONE);
lvMyComments.setVisibility(View.VISIBLE);
CommentsAdapter commentsAdapter = new CommentsAdapter(
CommentsActivity.this, commentsList);
lvMyComments.setAdapter(commentsAdapter);
}
} else{
progressLayout.setVisibility(View.GONE);
tvNoComments.setVisibility(View.VISIBLE);
lvMyComments.setVisibility(View.GONE);
}
}
private void getCommentsFromDb() {
db.openDatabase();
Cursor c = db.getComments();
if (c != null) {
commentsList = null;
commentsList = new ArrayList<CommentsBean>();
if (c.moveToFirst()) {
do {
CommentsBean mBeanClass = new CommentsBean();
mBeanClass
.setCommentText(c.getString(c
.getColumnIndex(db.KEY_COMMENT_TEXT)));
mBeanClass
.setCommentedDate(c.getString(c
.getColumnIndex(db.KEY_COMMENT_DATE)));
mBeanClass
.setCommentedBy(c.getString(c
.getColumnIndex(db.KEY_COMMENT_USER)));
commentsList.add(mBeanClass);
} while (c.moveToNext());
}
}
c.close();
db.closeDatabase();
}
}
comments_layout.xml
<RelativeLayout
android:id="#+id/commentsBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="#dimen/margin_5"
android:layout_marginLeft="#dimen/margin_2"
android:layout_marginRight="#dimen/margin_5" >
<Button
android:id="#+id/btnPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="#dimen/margin_35"
android:background="#color/coupon_color"
android:paddingBottom="#dimen/margin_7"
android:paddingLeft="#dimen/margin_15"
android:paddingRight="#dimen/margin_15"
android:paddingTop="#dimen/margin_7"
android:layout_alignParentRight="true"
android:layout_marginRight="#dimen/margin_2"
android:text="Post"
android:visibility="gone"
android:textColor="#color/white"
android:textSize="#dimen/normal_textsize" />
<EditText
android:id="#+id/etAddComment"
android:layout_width="match_parent"
android:layout_alignParentLeft="true"
android:layout_marginLeft="#dimen/margin_2"
android:layout_toLeftOf="#id/btnPost"
android:layout_marginRight="#dimen/margin_2"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_5"
android:hint="#string/comment_hint" />
</RelativeLayout>
<ListView
android:id="#+id/lvMyComments"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginBottom="#dimen/margin_5"
android:divider="#color/home_bg_color"
android:dividerHeight="#dimen/divider_height"
android:scrollbars="none"
android:visibility="gone" >
</ListView>
<RelativeLayout
android:id="#+id/progressLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/commentsBox"
android:layout_marginLeft="#dimen/margin_10"
android:layout_marginRight="#dimen/margin_10" >
<ProgressBar
android:id="#+id/pBarComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateDrawable="#drawable/circular_progress_bar" />
<TextView
android:id="#+id/tvWaitComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/pBarComments"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/margin_5"
android:layout_marginRight="#dimen/margin_5"
android:text="Loading comments..."
android:textColor="#color/black"
android:textSize="#dimen/small_textsize" />
</RelativeLayout>
<TextView
android:id="#+id/tvNoComments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/etAddComment"
android:layout_marginLeft="#dimen/margin_15"
android:layout_marginRight="#dimen/margin_25"
android:gravity="center_vertical|center_horizontal"
android:text="No comments have been posted for this offer"
android:textColor="#color/black"
android:textSize="#dimen/normal_textsize"
android:visibility="gone" />
CommentsAdapter.java
public class CommentsAdapter extends BaseAdapter {
private Context context;
private ArrayList<CommentsBean> mArrayList = new ArrayList<CommentsBean>();
public CommentsAdapter(Context ctx, ArrayList<CommentsBean> arrayList) {
this.context = ctx;
this.mArrayList = arrayList;
}
#Override
public int getCount() {
return mArrayList.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view;
view = null;
convertView = null;
if (convertView == null) {
view = new View(context);
view = inflater.inflate(R.layout.list_comments, null);
TextView commentText = (TextView) view
.findViewById(R.id.commentText);
TextView postedDate = (TextView) view.findViewById(R.id.postedDate);
TextView userName = (TextView) view.findViewById(R.id.userName);
commentText.setText(mArrayList.get(position).getCommentText());
userName.setText(" - " + mArrayList.get(position).getCommentedBy());
String dt = mArrayList.get(position).getCommentedDate();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d = null;
try {
d = sdf.parse(dt);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy");
String convertedDate = null;
convertedDate = sdf1.format(d);
postedDate.setText(convertedDate);
}
return view;
}
}
list_comments.xml
<ImageView android:id="#+id/cmtIcon"
android:layout_width="#dimen/margin_25"
android:layout_height="#dimen/margin_25"
android:src="#drawable/comment_list_icon"
android:layout_alignParentTop="true"
android:layout_marginTop="#dimen/margin_5"
android:layout_marginLeft="#dimen/margin_5"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/commentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_10"
android:layout_toRightOf="#id/cmtIcon"
android:layout_alignParentTop="true"
android:layout_marginTop="#dimen/margin_5"
android:textColor="#color/black"
android:textSize="#dimen/normal_textsize" />
<TextView
android:id="#+id/postedDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/commentText"
android:layout_toRightOf="#id/cmtIcon"
android:layout_marginLeft="#dimen/margin_10"
android:layout_marginTop="#dimen/margin_5"
android:text="Posted on"
android:textColor="#color/black"
android:textSize="#dimen/small_textsize" />
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/postedDate"
android:layout_marginTop="#dimen/margin_3"
android:text="User Name"
android:layout_below="#id/commentText"
android:textColor="#color/black"
android:textSize="#dimen/normal_textsize" />

how to do onclick child view(button) using OnItemClickListener in listview

can any one give me the example/ help me how to do onclick button to next activity. My custom listview contains texts, button and scroll index.. i am geting problem in on click button.. i tried a lot from 3 days but no use.. if can any one say me how to do using onitemclickchildview(button(btnlist).. as i seen in some doc they told that listview is a parent and inside listview item/content/data
is child.. i want child button(btnlist) to onclick. please help it.. thank u in advance.
homemplebrowview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:descendantFocusability="beforeDescendants"
android:padding="5dip" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="100dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textColor="#663333"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/name"
android:layout_alignParentBottom="true"
android:layout_marginBottom="21dp"
android:textColor="#666666"
android:text="MRN:" />
<TextView
android:id="#+id/mrn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView4"
android:layout_alignBottom="#+id/textView4"
android:layout_marginLeft="24dp"
android:textColor="#666666"
android:layout_toRightOf="#+id/textView4"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/name"
android:layout_marginLeft="63dp"
android:layout_toRightOf="#+id/mrn"
android:textColor="#666666"
android:text="Actual Start Date:"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/mrn"
android:layout_alignBottom="#+id/mrn"
android:layout_alignLeft="#+id/textView2"
android:textColor="#666666"
android:text="Age:"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView6"
android:layout_below="#+id/textView6"
android:textColor="#666666"
android:text="Gender"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView6"
android:layout_marginLeft="58dp"
android:layout_toRightOf="#+id/textView2"
android:textColor="#666666"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView6"
android:layout_alignBottom="#+id/textView6"
android:layout_alignRight="#+id/date"
android:textColor="#666666"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView7"
android:layout_alignBottom="#+id/textView7"
android:layout_alignLeft="#+id/age"
android:textColor="#666666"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/date"
android:layout_alignBottom="#+id/date"
android:layout_marginLeft="119dp"
android:layout_toRightOf="#+id/date"
android:textColor="#666666"
android:text="Ward No:"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/age"
android:layout_alignBottom="#+id/age"
android:layout_alignLeft="#+id/textView3"
android:textColor="#666666"
android:text="Room No:"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView12"
android:layout_alignParentBottom="true"
android:textColor="#666666"
android:text="Bed No:"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/wardno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView3"
android:layout_alignBottom="#+id/textView3"
android:layout_marginLeft="60dp"
android:layout_toRightOf="#+id/textView3"
android:textColor="#666666"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/roomno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView12"
android:layout_alignBottom="#+id/textView12"
android:layout_alignLeft="#+id/wardno"
android:textColor="#666666"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/bedno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView13"
android:layout_alignBottom="#+id/textView13"
android:layout_alignLeft="#+id/roomno"
android:textColor="#666666"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="#+id/listbutton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/name"
android:layout_marginRight="43dp"
android:focusable="false"
android:text="Episode"
android:textColor="#666666" />
</RelativeLayout>
</RelativeLayout>
MainActivity.java
public class MainActivity extends Activity implements
SearchView.OnQueryTextListener, SearchView.OnCloseListener, OnClickListener{
private ListView listView;
private SearchView search;
EfficientAdapter objectAdapter;
int textlength = 0;
private CheckBox checkStat, checkRoutine, checkTat;
private ArrayList<Patient> patientListArray;
private Patient patient;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.homempleb);
Log.i("scan", " txtScanResult ");
ActionItem nextItem = new ActionItem();
final QuickAction quickAction = new QuickAction(this,
QuickAction.VERTICAL);
quickAction.addActionItem(nextItem);
quickAction.setOnDismissListener(new QuickAction.OnDismissListener() {
#Override
public void onDismiss() {
Toast.makeText(getApplicationContext(), "Dismissed",
Toast.LENGTH_SHORT).show();
}
});
listView = (IndexableListView) findViewById(R.id.homelistView);
//listView = (ListView) findViewById(R.id.homelistView);
listView.setTextFilterEnabled(true);
listView.setFastScrollEnabled(true);
//listView.setItemsCanFocus(true);
listView.setClickable(false);
listView.addStatesFromChildren();
objectAdapter = new EfficientAdapter(this);
listView.setAdapter(objectAdapter);
}
#Override
public boolean onClose() {
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
return false;
}
#Override
public boolean onQueryTextSubmit(String query) {
return false;
}
**
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "STAT", Toast.LENGTH_SHORT).show();
Intent next = new Intent(MainActivity.this, SeviceDetails.class);
// Log.i("patient", " next "+ position + " onclickposition " + patientListArray.get(position).getMrnNumber());
Log.i("DDDD ", patient.getMrnNumber());
System.out.println("patient"+ patient);
startActivity(next);
}
**
}
EfficientAdapter.java
public class EfficientAdapter extends BaseAdapter implements SectionIndexer {
IndexableListView mListView;
private String mSections = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ArrayList<Patient> patientListArray;
private Intent intent;
private Patient patient;
private LayoutInflater mInflater;
private Context context;
private int positions;
ViewHolder holder;
private String position;
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
this.context = context;
String patientListJson = CountriesList.jsonData;
JSONObject jssson;
try {
jssson = new JSONObject(patientListJson);
patientListJson = jssson.getString("PostPatientDetailResult");
} catch (JSONException e) {
e.printStackTrace();
}
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonArray Jarray = parser.parse(patientListJson).getAsJsonArray();
patientListArray = new ArrayList<Patient>();
for (JsonElement obj : Jarray) {
Patient patientList = gson.fromJson(obj, Patient.class);
patientListArray.add(patientList);
// Log.i("patientList", patientListJson);
}
}
public int getCount() {
return patientListArray.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
this.positions = position;
View rowView = convertView;
if (rowView == null) {
Log.i("row", "Inside IF");
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.homemplebrowview, null);
holder = new ViewHolder();
holder.text1 = (TextView) rowView.findViewById(R.id.name);
holder.text2 = (TextView) rowView.findViewById(R.id.mrn);
holder.text3 = (TextView) rowView.findViewById(R.id.date);
holder.text4 = (TextView) rowView.findViewById(R.id.age);
holder.text5 = (TextView) rowView.findViewById(R.id.gender);
holder.text6 = (TextView) rowView.findViewById(R.id.wardno);
holder.text7 = (TextView) rowView.findViewById(R.id.roomno);
holder.text8 = (TextView) rowView.findViewById(R.id.bedno);
** holder.btnList = (Button) rowView.findViewById(R.id.listbutton);**
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
Log.i("row", "Inside ELSE");
holder.text1.setText(Util.formatN2H(patientListArray.get(position)
.getName()));
holder.text2.setText(patientListArray.get(position).getMrnNumber());
holder.text3.setText(Util.formatN2H(patientListArray.get(position)
.getRoom()));
holder.text4.setText(Util.formatN2H(patientListArray.get(position)
.getAge()));
holder.text5.setText(Util.formatN2H(patientListArray.get(position)
.getGender()));
holder.text6.setText(Util.formatN2H(patientListArray.get(position)
.getWard()));
holder.text7.setText(Util.formatN2H(patientListArray.get(position)
.getRoom()));
holder.text8.setText(Util.formatN2H(patientListArray.get(position)
.getBed()));
** holder.btnList.setOnClickListener(((MainActivity) context)); **
return rowView;
}
static class ViewHolder {
public Button btnList;
public TextView text8;
public TextView text7;
public TextView text6;
public TextView text5;
public TextView text4;
public TextView text1;
public TextView text2;
public TextView text3;
}
#Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
public int getPositionForSection(int section) {
sortMyData();
Log.i("getPositionForSection", "section" + section);
// If there is no item for current section, previous section will be
// selected
for (int i = section; i >= 0; i--) {
for (int j = 0; j < getCount(); j++) {
if (i == 0) {
Log.i("getPositionForSection- i", "section" + i);
// For numeric section
for (int k = 0; k <= 9; k++) {
if (StringMatcher.match(
String.valueOf(patientListArray.get(j)
.getName().charAt(0)),
String.valueOf(k)))
Log.i("getPositionForSection- j", "section" + j);
return j;
}
} else {
if (StringMatcher.match(
String.valueOf(patientListArray.get(j).getName()
.charAt(0)),
String.valueOf(mSections.charAt(i))))
return j;
}
}
}
return 0;
}
public int getSectionForPosition(int position) {
return 0;
}
public Object[] getSections() {
String[] sections = new String[mSections.length()];
for (int i = 0; i < mSections.length(); i++)
sections[i] = String.valueOf(mSections.charAt(i));
return sections;
}
/**
* sorting the patientListArray data
*/
public void sortMyData() {
// sorting the patientListArray data
Collections.sort(patientListArray, new Comparator<Object>() {
#Override
public int compare(Object k1, Object k2) {
Patient p1 = (Patient) k1;
Patient p2 = (Patient) k2;
return p1.getName().compareToIgnoreCase(p2.getName());
}
});
}
I am not sure about your code, its too tedious to go through. But i have had the same problems before and I solved it as follows. In your adapter you need to set the on click listener for that button and add a tag to it.
holder.btnList.setOnClickListener(((MyActivity) context));
Where context is the Context that you pass to the adapter and the MyActivity is whatever activity in which the click is to be handled. So when you click the button then the MyActivity's on click listener will be called. You can also add tags to the holder object if you want any data to be passed. Then in your MyActivity where you implement the onClickListener. You handle whatever events you want in the MyActivity. Please post further doubts if you have any.
holder.btnList.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
//youre code
}
);

Categories

Resources