Question

In custom ListView all rows are empty! .. the data not appear! I do not know where the problem actually, I execute the same .apk file on many devices, however, it is run correctly on all of them except android device with version 4.1.1. Really I can't know where is the problem for apk to run on one device and not on the other one?! (this will lead me to mad)..

The custom ListView code (I am sure the problem is not in code, cause it is run on the other devices and data appear on ListView):

public class ListViewCustomAdapter extends BaseAdapter {
public String title[];
public String description[];
public String curr[];
public int size,fontsize;
public Activity context;
public LayoutInflater inflater;

public showAccounts accounts;

public ListViewCustomAdapter(Activity context,String[] title, String[] description, String[] curr) {
    super();

    this.context = context;
    this.accounts=new showAccounts();
    this.title = title;
    this.description = description;
    this.curr = curr;
    this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

public int getCount() {
    // TODO Auto-generated method stub
    return title.length;
}

public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
}

public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

public static class ViewHolder {
    ImageView imgViewLogo;
    TextView txtViewTitle;
    TextView txtViewDescription;
    TextView txtViewcurr;
}


public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    ViewHolder holder;
    //Define the size of layout 
    size=accounts.getsize();
    fontsize=accounts.getfont();

    if(convertView==null){
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.accountlist, null);

        holder.txtViewTitle = (TextView) convertView.findViewById(R.id.textView);
        holder.txtViewTitle.setWidth(size*2); 
        holder.txtViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP,fontsize);

        holder.txtViewDescription = (TextView) convertView.findViewById(R.id.textView1);
        holder.txtViewDescription.setWidth(size);   
        holder.txtViewDescription.setTextSize(TypedValue.COMPLEX_UNIT_SP,fontsize);

        holder.txtViewcurr = (TextView) convertView.findViewById(R.id.textView2);
        holder.txtViewcurr.setWidth(size/2);   
        holder.txtViewcurr.setTextSize(TypedValue.COMPLEX_UNIT_SP,fontsize);

        if ( position % 2 == 0 ){
            convertView.setBackgroundColor(Color.parseColor("#96c4fa"));

        }else{
            convertView.setBackgroundColor(Color.parseColor("#e9e9e9"));
        }

        convertView.setTag(holder);

    } else {
        holder=(ViewHolder)convertView.getTag();
        if ( position % 2 == 0 ){
            convertView.setBackgroundColor(Color.parseColor("#96c4fa"));

        }else{
            convertView.setBackgroundColor(Color.parseColor("#e9e9e9"));
        }
    }

    holder.txtViewTitle.setText(title[position]);
    holder.txtViewDescription.setText(description[position]);
    holder.txtViewcurr.setText(curr[position]);

    return convertView;
}
}

accountlist.xml code:

  <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:orientation="horizontal">

<TextView
       android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/black"
        android:gravity="right"

 />
<TextView
       android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/black"
        android:gravity="right"

 />

<TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/black"
        android:gravity="right"

        />

 <ImageView
        android:id="@+id/imageView"
        android:src="@drawable/wuser"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="right"/>

  </LinearLayout>
  • I attempt to execute the apk on real device via Eclipse to see where is the problem (BUT the device does not appear in list).
  • I do not think that the problem in code, since the same code for apk run on other devices
  • Or the problem maybe related to usage space for apk? I do not know actually!
  • You can see please the two images that explain my problem.

enter image description here

Any help will be appreciated,

Edit

my problem was solved! I just reset the device and everything goes well! Really, before, I do not think that the viruses can cause like these problems, such affects to other applications,etc. However, its good to note and know that after this long time to solve this problem!

Was it helpful?

Solution

Your problem is in setting the width of text views in the correct way and the same thing for the text size. So, try to delete or comment the code that is related in setting widths and sizes such these lines of code

 holder.txtViewTitle.setWidth(size*2); 
 holder.txtViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP,fontsize);

After that run the code over your particular simulator or device, then you will see the appearance of your texts. Note that (from my point of view) it is wrong to fix the size of font and the width of the views, so you have to find a way to adapt the sizes based on the screen width of the devices.

OTHER TIPS

First you initialize variable title, description and curr.

For eg. this.title=new title[title.length];

Same as above initialize all the array variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top