Create GridView set IMAGE in sketchware




// In Add OnCreate 
//Image position
{
HashMap<String, Object> _item = new HashMap<>();
_item.put("name", "image position name");
listmap.add(_item);
}

//Grid view position

GridView grid = new GridView(this);
grid.setLayoutParams(new GridView.LayoutParams(GridLayout.LayoutParams.MATCH_PARENT, GridLayout.LayoutParams.WRAP_CONTENT));
grid.setBackgroundColor(Color.WHITE);
grid.setNumColumns(3);
grid.setColumnWidth(GridView.AUTO_FIT);
grid.setVerticalSpacing(5);
grid.setHorizontalSpacing(5);
grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
grid.setAdapter(new Listview1Adapter(listmap));
linear1.addView(grid);
grid.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
showMessage(Integer.toString(position));
}});

}
private String name = "";
private ArrayList<HashMap<String, Object>> listmap = new ArrayList<>();
public class Listview1Adapter extends BaseAdapter {
ArrayList<HashMap<String, Object>> _data;
public Listview1Adapter(ArrayList<HashMap<String, Object>> _arr) {
_data = _arr;
}

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

@Override
public HashMap<String, Object> getItem(int _i) {
return _data.get(_i);
}

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

@Override
public View getView(final int _position, View _view, ViewGroup _viewGroup) {
LayoutInflater _inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View _v = _view;
if (_v == null) {
_v = _inflater.inflate(R.layout.custom_name, null);
}

//custom view

final LinearLayout linear1 = (LinearLayout) _v.findViewById(R.id.linear1);
final ImageView imageview1 = (ImageView) _v.findViewById(R.id.imageview1);
final TextView textview1 = (TextView) _v.findViewById(R.id.textview1);

name = _data.get((int)_position).get("name").toString();
textview1.setText(name);



//Set Image

if (name.equals("image position name")) {
imageview1.setImageResource(R.drawable.image_name);
}

//End of code

return _v;
}
}
public void nothing() {


video Help





Post a Comment

Previous Post Next Post