如何在gridview

时间:2018-01-06 09:48:14

标签: android gridview

我有一个应用程序,其中我有一个自定义网格视图,其中包含图像和文本视图以及在网格视图中填充数据的适配器。我有三个不同类型的项目,我在视图中填充.PLease查找类型和视图的视图详细信息

查看: a)ImageView b)TextView

数据: a)TextDrawable img b)字符串名称 c)String imageUrl

现在,我想在Imageview中设置img和imageurl。如果我得到了img =“String”,那么在imageView中设置ImageDrawable,如果我得到imageUrl =“http ...”,那么在Imageview中设置该图像。何我这样做请帮助。

数据模型代码

 private String name;
private TextDrawable img;
private String imageurl;


public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public TextDrawable getImg() {
    return img;
}

public void setImg(TextDrawable img) {
    this.img = img;
}

public String getImageurl() {
    return imageurl;
}

public void setImageurl(String imageurl) {
    this.imageurl = imageurl;
}

适配器类的代码

private ArrayList<UserListingModel> dataModel;
Context context;
private static LayoutInflater inflater = null;

public NameListingAdapter(Context context, ArrayList<UserListingModel> models) {
    this.context = context;
    this.dataModel = models;
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return dataModel.size();
}

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

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

public class Holder {
    TextView tv;
    CircleImageView img;
}

@Override
public View getView(final int position, final View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    Holder holder = new Holder();
    View rowView;
    rowView = inflater.inflate(R.layout.main_name_list_items, null);
    holder.tv = (TextView) rowView.findViewById(R.id.textView1);
    holder.img = (CircleImageView) rowView.findViewById(R.id.profile_image);


    holder.tv.setText(dataModel.get(position).getName());
    holder.img.setImageDrawable(dataModel.get(position).getImage());
    rowView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(context, DashBoardMain.class);
            i.putExtra("Name", dataModel.get(position).getName());
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }
    });
    return rowView;
}

总的来说,我想要做的是在GridView ImageVie / w

中设置不同的类型

0 个答案:

没有答案