mercredi 27 mai 2015

Horizontal ListView is not working properly

I am using TwoWayView library from Lucas to create a horizontal ListView. Everything works fine on GS3, Galaxy Note 2 Android 4.1.2 & Android 4.3.

However, I installed my app on my coworker Motorola G Android 4.44, and the ListView did not show any image. I can click on them, but I can't see any image. It only shows red or transparent color.

ListView Adpater:

public class ListViewAdapter extends BaseAdapter {
    private List<ListViewObject> ObjectList;
    private Context mContext;

    public ListViewAdapter(Context context, List<ListViewObject> newList){
    this.mContext = context;
    this.ObjectList = newList;
}

@Override
public int getCount() {
    return ObjectList.size();
}

@Override
public ListViewObject getItem(int position) {
    return ObjectList.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {       
  ViewHolder viewHolder = new ViewHolder();

  LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  if (convertView == null) {
      convertView = inflater.inflate(R.layout.listview_layout, parent, false);
      viewHolder.imageView = (ImageView)convertView.findViewById(R.id.ListViewImage); 
      viewHolder.layout = (RelativeLayout)convertView.findViewById(R.id.ListViewLayout);
      convertView.setTag(viewHolder);            
  } 
 else 
  {
     viewHolder = (ViewHolder)convertView.getTag();
  }

  Picasso.with(mContext)
  .load(getItem(position).getImageUrl())
  .resize(100, 100)  
  .centerCrop()
  .into(viewHolder.imageView);   

  return convertView;
}

class ViewHolder {
    RelativeLayout layout;
    ImageView imageView;
}

}

ListView Layout:

<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:id="@+id/ListViewLayout"    
android:layout_width="52dp"
android:layout_height="43dp" >

<ImageView
    android:id="@+id/ListViewImage"
    android:layout_width="50dp"
    android:layout_height="40dp"
    android:scaleType="fitXY"
    android:layout_marginLeft="2px"
    android:layout_marginTop="2px" />

Main Layout:

<org.lucasr.twowayview.TwoWayView
    xmlns:android="http://ift.tt/nIICcg"
    xmlns:app="http://ift.tt/GEGVYd"
    android:id="@+id/TwoWayView"
    style="@style/TwoWayView"
    android:layout_width="match_parent"
    android:layout_height="43dp"
    android:layout_marginTop="595dp"
    android:background="@color/transparent"
    android:drawSelectorOnTop="true" />

MainActivity:

 public void ListView_Load() {
        for (File file : listFile){
            mListViewObject = new ListViewObject();
            mListViewObject.setImageUrl("file:///" + file.getAbsolutePath());
            ListViewObject_List.add(mListViewObject); 
        }        
        listViewAdapter = new ListViewAdapter(this, ListViewObject_List);
        TwoWayListView.setAdapter(listViewAdapter);
} 

I just can't figure it out why this is happening.

can someone please guide me on this?

Thank you very much for your help.

Aucun commentaire:

Enregistrer un commentaire