Widget - GridView Custome

//Add OnCreate

{
HashMap<String, Object> _item = new HashMap<>();
_item.put("name", "google");
listmap.add(_item);
}

{
HashMap<String, Object> _item = new HashMap<>();
_item.put("name", "facebook");
listmap.add(_item);
}

{
HashMap<String, Object> _item = new HashMap<>();
_item.put("name", "youtube");
listmap.add(_item);
}

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.custome, null);
}
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);
if (name.equals("google")) {
imageview1.setImageResource(R.drawable.google);
}
return _v;
}
}

public void nothing() {

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

TextInputLayout in Sketchware

How to find and​ highlight a word in a text field in Sketchware?

A Flash Light App in Sketchware

How to enable download in webview in Sketchware apps?

Intent - Open File By Type

Code for implementing Notifications in Sketchware

How to share an image from Drawable folder?

ActionBar back button

Animation Transtition Animation