我想在网格视图中显示用户(使用用户图像)我的jsonArray正在给我正确的响应(User_id,User_image,User_full of 3 Users)
我的问题是如何在网格视图中显示三个用户并且可以点击
是否有任何示例在GRID VIEW中显示这些用户...我知道我必须设置适配器但是如何????????
[3]
0: {
User_Id: "47"
User_Full_Name: "pragya Singh"
User_Image: "http://www.get2love.webitexperts.com/profile_images/1400734158bg.jpg"
}-
1: {
User_Id: "57"
User_Full_Name: "meet"
User_Image: ""
}-
2: {
User_Id: "67"
User_Full_Name: "meet"
User_Image: ""
}
答案 0 :(得分:0)
以下是网格适配器示例。您可以将用户对象数组传递给网格适配器,为每个用户行设计布局,并在getView()方法中,根据数组中的位置来扩展布局并设置视图的值。
import java.util.ArrayList;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
public class GridAdapter extends BaseAdapter {
private ArrayList<Drawable> images;
LayoutInflater inflater;
public GridAdapter(Context context, ArrayList<Drawable> images,
int backgroundType) {
this.images = images;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return images.size();
}
@Override
public Object getItem(int position) {
return images.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.grid_item, null);
}
ImageView ivImage = (ImageView) convertView.findViewById(R.id.ivImage);
ivImage.setImageDrawable(images.get(position));
return convertView;
}
}