2016-04-19 3 views
-1

Ich versuche, zwei verschiedene Bilder in einer einzigen Liste-View Zeile mit Volley, aber jedes Mal, wenn ich die gleichen Bilder in beiden Bild-Ansicht (Netzwerk-) Bild-Ansicht) und wenn ich auf ein Bild klicke, blicke auf die ganze Zeile. Ich bin neu in Android und Codierung bitte helfen.Wie bekomme ich zwei verschiedene Bilder in der Listview Zeile mit Volley

public class CustomListAdapter extends BaseAdapter { 
private Activity activity; 
private LayoutInflater inflater; 
private List<Movie> movieItems; 
ImageLoader imageLoader = MyApplication.getInstance().getImageLoader(); 

public CustomListAdapter(Activity activity, List<Movie> movieItems) { 
    this.activity = activity; 
    this.movieItems = movieItems; 
} 

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

@Override 
public Object getItem(int location) { 
    return movieItems.get(location); 
} 

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

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 

    if (inflater == null) 
     inflater = (LayoutInflater) activity 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    if (convertView == null) 
     convertView = inflater.inflate(R.layout.list_row, null); 

    if (imageLoader == null) 
     imageLoader = MyApplication.getInstance().getImageLoader(); 
    NetworkImageView thumbNail = (NetworkImageView) convertView 
      .findViewById(R.id.thumbnail); 
    NetworkImageView thumbNail2 = (NetworkImageView) convertView 
      .findViewById(R.id.thumbnail2); 

    // getting movie data for the row 
    Movie m = movieItems.get(position); 

    // thumbnail image 
    thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader); 
    thumbNail2.setImageUrl(m.getThumbnailUrl(), imageLoader); 

    // title 
    return convertView; 
} 

}

list_row

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="200dp" 
    android:weightSum="2" 
    android:layout_weight="1" 
    android:orientation="horizontal"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"> 

     <com.android.volley.toolbox.NetworkImageView 
      android:id="@+id/thumbnail" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:scaleType="fitXY" 
      android:layout_marginLeft="1dp" 
      android:layout_marginRight="1dp" 
      android:layout_marginTop="1dp" /> 
      /> 





     <TextView 
      android:elevation="6dp" 
      android:id="@+id/category_title_one" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Title" 
      android:textSize="20dp" 
      android:layout_alignParentBottom="true" 
      android:layout_margin="12dp" 
      android:textColor="@android:color/white" 
      /> 



    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"> 

     <com.android.volley.toolbox.NetworkImageView 
      android:id="@+id/thumbnail2" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:scaleType="fitXY" 
      android:layout_marginLeft="1dp" 
      android:layout_marginRight="1dp" 
      android:layout_marginTop="1dp" 
      android:layout_alignParentBottom="true" /> 




     <TextView 
      android:elevation="6dp" 
      android:id="@+id/category_title_two" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Title" 
      android:textSize="20dp" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      android:layout_margin="12dp" 
      android:textColor="@android:color/white" 
      /> 


    </RelativeLayout> 
</LinearLayout> 

+1

post ur code hier? –

+0

Wie poste ich ??? –

+0

zeigen einige Code bitte –

Antwort

0
thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader); 
thumbNail2.setImageUrl(m.getThumbnailUrl(), imageLoader); 

Wie Sie feststellen, können Sie auf gleiche Thumbnail sind vorbei sowohl die imageviews.Also Sie laden müssen zwei Movie an einer Position zur Anzeige Beide Bilder. Verwenden Sie besser GridView oder noch besser verwenden Sie Recyclerview mit GridLayoutManager. Wenn Sie die ListView verwenden möchten, führen Sie die folgenden Änderungen.

@Override 
public int getCount() { 
    int size = movieItems.size()/2; 
    return size ==0 ? size : size +1;// +1 for odd number of items like 3 or 5 or 7 ..so on. 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    //And also you have handle the odd Items case.Better add extra null at the end if you have odd number of items 
    if(position != 0){ 
     position = 2 * position; 
    } 
    Movie m1 = movieItems.get(position); 
    Movie m2 = movieItems.get(position+1); 
    thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader); 
    thumbNail2.setImageUrl(m.getThumbnailUrl(), imageLoader); 
} 
+0

Gajjab = D ... danke Bhaiya Ji;) –

Verwandte Themen