I have created a custom adapter to set values to textview and other components in a listview but on some devices the value to Textview is not set and shows the default value which is used while designing.
In below code the txtAmount is not set and other textview value is set,but this issue is only in some devices
public class ImageCustomList extends ArrayAdapter<String> {
private final Activity context;
private final String[] name;
private final String[] imagepath;
private final String[] address;
private final String city[];
private final String pincode[];
private final String ISO[];
private final String NABL[];
private final String CAP[];
private final String Service[];
private final String HomeCollection[];
private final String Amount[];
private final String DiscountedAmount[];
private final String Test[];
private final String TestAmount[];
private final double HomeCollectionCharges[];
private final String FlagSearchFrom;
customButtonListener customListner;
public interface customButtonListener {
public void onButtonClickListner(int position,String value);
}
public void setCustomButtonListner(customButtonListener listener) {
this.customListner = listener;
}
public ImageCustomList(Activity context,String[] name,String [] imagepath, String [] address,String [] city,String [] pincode,String [] ISO,String [] NABL,String [] CAP,String [] Service,String []HomeCollection,String [] Amount,String [] DiscountedAmount,String [] Test, String [] TestAmount,double [] HomeCollectionCharges,String FlagSearchFrom) {
super(context, R.layout.list_row,name);
this.context = context;
this.name = name;
this.imagepath=imagepath;
this.address = address;
this.city=city;
this.pincode=pincode;
this.ISO=ISO;
this.NABL=NABL;
this.CAP=CAP;
this.Service=Service;
this.HomeCollection=HomeCollection;
this.Amount=Amount;
this.DiscountedAmount=DiscountedAmount;
this.Test=Test;
this.TestAmount=TestAmount;
this.HomeCollectionCharges=HomeCollectionCharges;
this.FlagSearchFrom=FlagSearchFrom;
}
@Override
public View getView(final int position,View view,ViewGroup viewGroup) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.list_row, null, true);
TextView txtName = (TextView) rowView.findViewById(R.id.title);
ImageView imgView =(ImageView)rowView.findViewById(R.id.list_image);
TextView txtCAP=(TextView)rowView.findViewById(R.id.txtISO);
TextView txtCity=(TextView)rowView.findViewById(R.id.city);
TextView txtAmount=(TextView)rowView.findViewById(R.id.txtAmount);
TextView txtDiscountedAmount=(TextView)rowView.findViewById(R.id.txtDiscounted);
TextView txtIndividualTest=(TextView)rowView.findViewById(R.id.txtIndividualTest);
TextView txtHomeCollection=(TextView)rowView.findViewById(R.id.txtHomeCharges);
String test_comma_sep=Test[position];
String amount_comma_sep=TestAmount[position];
ArrayList<String> lstTest=new ArrayList<>(Arrays.asList(test_comma_sep.split(",")));
ArrayList<String> lstAmount=new ArrayList<>(Arrays.asList(amount_comma_sep.split(",")));
String create_indi_test_amt_text="";
for(int i=0;i<lstTest.size();i++) {
create_indi_test_amt_text=create_indi_test_amt_text+lstTest.get(i).toString()+" - Rs."+lstAmount.get(i).toString();
if(i!=lstTest.size()) {
create_indi_test_amt_text=create_indi_test_amt_text+"\n";
}
}
txtIndividualTest.setText(create_indi_test_amt_text);
int loader = R.drawable.ic_logoheart;
txtName.setText(name[position]);
ViewHolder holder=new ViewHolder();
holder.btnBook=(Button)rowView.findViewById(R.id.btnBook);
holder.btnBook.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
customListner.onButtonClickListner(position,"Book");
}
});
txtCAP.setText(Html.fromHtml(lab_Feature));
txtCity.setText(city[position]);
if(DiscountedAmount[position].equals("")) {
txtAmount.setTextColor(Color.parseColor("#0391D1"));
txtDiscountedAmount.setText("");
if(FlagSearchFrom.equals("Test")) {
if(HomeCollectionCharges[position]==0){
txtHomeCollection.setText("Home Collection Charges:FREE");
txtAmount.setText("Rs." + Amount[position]);
}
else{
txtHomeCollection.setText("Home Collection Charges: Rs."+HomeCollectionCharges[position]);
txtAmount.setText("Rs." + Amount[position]);
}
}
else {
txtAmount.setText("Rs." + Amount[position]);
txtHomeCollection.setVisibility(View.GONE);
}
}
else{
txtAmount.setPaintFlags(txtAmount.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
txtDiscountedAmount.setText("Rs." + DiscountedAmount[position]);
if(FlagSearchFrom.equals("Test")) {
if(HomeCollectionCharges[position]==0){
txtHomeCollection.setText("Home Collection Charges:FREE");
txtAmount.setText("Rs." + Amount[position]);
}
else{
txtHomeCollection.setText("Home Collection Charges: Rs."+HomeCollectionCharges[position]);
txtAmount.setText("Rs." + Amount[position]);
txtDiscountedAmount.setText("Rs." + DiscountedAmount[position]);
}
}
else {
txtAmount.setText("Rs." + Amount[position]);
txtHomeCollection.setVisibility(View.GONE);
}
}
try {
ImageLoader imgLoader = new ImageLoader(getContext().getApplicationContext());
imgLoader.DisplayImage(imagepath[position], loader, imgView);
}
catch (Exception ex){
}
return rowView;
}
public class ViewHolder {
Button btnBook;
}
}
="1.0"="utf-8"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:removed="@drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_removed"
android:layout_height="wrap_removed"
android:layout_alignTop="@+id/logo"
android:layout_alignParentLeft="true"
android:textColor="#3D3D3D"
android:typeface="sans"
android:textSize="19sp"
android:textStyle="bold"
android:text="Title"
/>
<LinearLayout
android:id="@+id/linearAmt"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_alignParentLeft="true">
<TextView
android:id="@+id/txtAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF0000"
android:textSize="16sp"
android:text="Rs.1234.00"
android:layout_weight="1"/>
<TextView
android:id="@+id/txtDiscounted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#0391D1"
android:textSize="21sp"
android:paddingLeft="16sp"
android:layout_below="@+id/title"
android:text="Rs.1000.00"
android:layout_weight="1"/>
</LinearLayout>
<TextView
android:id="@+id/txtHomeCharges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFA500"
android:textSize="8sp"
android:layout_below="@+id/linearAmt"
android:text="Home Collection Charges: Rs.100.00"
/>
<TextView
android:id="@+id/txtIndividualTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtHomeCharges"
android:textColor="#000000"
android:textSize="8sp"
android:layout_marginTop="1dip"
android:layout_toLeftOf="@+id/logo"
android:layout_alignParentLeft="true"
android:singleLine="false"
android:paddingRight="5sp"
android:text="Just gona \n stand \n there and ...\n" />
<TextView
android:id="@+id/city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#7D7D7D"
android:textSize="16sp"
android:layout_marginTop="1dip"
android:layout_below="@+id/txtIndividualTest"
android:layout_toLeftOf="@+id/logo"
android:layout_alignParentLeft="true"
android:text="City"/>
<TextView
android:id="@+id/txtISO"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#343434"
android:textSize="16sp"
android:layout_marginTop="3dip"
android:paddingLeft="2sp"
android:layout_below="@+id/city"
android:layout_toLeftOf="@+id/logo"
android:layout_alignParentLeft="true"
android:text="ISO Certified"
android:maxLines="5"
android:singleLine="false"/>
<LinearLayout android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="0dp"
android:paddingLeft="2dp"
android:layout_alignParentRight="true"
>
<ImageView
android:id="@+id/list_image"
android:layout_width="108sp"
android:layout_height="70dip"
android:scaleType="centerInside"
android:layout_gravity="center|top"
android:layout_marginRight="0dp"
/>
</LinearLayout>
<Button
android:id="@+id/btnBook"
android:layout_width="108sp"
android:layout_height="wrap_content"
android:text="BOOK"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:background="#FFA500"
android:layout_marginTop="5dp"
android:layout_below="@+id/logo"
android:layout_marginRight="0dp"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
What I have tried:
I tried to set a hardcoded value but its wrking fine in all devices