public class MainActivity extends AppCompatActivity {
GridView gridView;
ArrayList<HashMap<String, String>>arrayList = new ArrayList<>();
HashMap<String, String> hashMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView =findViewById(R.id.gridView);
createTable();
MyAdepter myAdepter = new MyAdepter();
gridView.setAdapter(myAdepter);
}
private class MyAdepter extends BaseAdapter {
@Override
public int getCount() {
return arrayList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = getLayoutInflater();
View myView = layoutInflater.inflate(R.layout.item, null);
ImageView imageView = myView.findViewById(R.id.imageView);
TextView textView = myView.findViewById(R.id.textView);
HashMap<String, String> hashMap = arrayList.get(position);
String image = hashMap.get("img");
String text = hashMap.get("txt");
imageView.setImageResource(Integer.parseInt(image));
textView.setText(text);
return myView;
}
} //***************************************************
private void createTable (){
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.send_many);
hashMap.put("txt", "Sand Many");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.mibile_recharge);
hashMap.put("txt", "Mobile Recharge");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.chash_out);
hashMap.put("txt", "Cash Out");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.pement);
hashMap.put("txt", "Payment");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.add_many);
hashMap.put("txt", "Add Many");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.pay_bill);
hashMap.put("txt", "Pay Bill");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.ticket);
hashMap.put("txt", "Ticket");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.more);
hashMap.put("txt", "More");
arrayList.add(hashMap);
}
GridView gridView;
ArrayList<HashMap<String, String>>arrayList = new ArrayList<>();
HashMap<String, String> hashMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView =findViewById(R.id.gridView);
createTable();
MyAdepter myAdepter = new MyAdepter();
gridView.setAdapter(myAdepter);
}
private class MyAdepter extends BaseAdapter {
@Override
public int getCount() {
return arrayList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = getLayoutInflater();
View myView = layoutInflater.inflate(R.layout.item, null);
ImageView imageView = myView.findViewById(R.id.imageView);
TextView textView = myView.findViewById(R.id.textView);
HashMap<String, String> hashMap = arrayList.get(position);
String image = hashMap.get("img");
String text = hashMap.get("txt");
imageView.setImageResource(Integer.parseInt(image));
textView.setText(text);
return myView;
}
} //***************************************************
private void createTable (){
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.send_many);
hashMap.put("txt", "Sand Many");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.mibile_recharge);
hashMap.put("txt", "Mobile Recharge");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.chash_out);
hashMap.put("txt", "Cash Out");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.pement);
hashMap.put("txt", "Payment");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.add_many);
hashMap.put("txt", "Add Many");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.pay_bill);
hashMap.put("txt", "Pay Bill");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.ticket);
hashMap.put("txt", "Ticket");
arrayList.add(hashMap);
hashMap = new HashMap<>();
hashMap.put("img",""+R.drawable.more);
hashMap.put("txt", "More");
arrayList.add(hashMap);
}
Post a Comment