public class MainActivity extends AppCompatActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ArrayList<PageData> data = new ArrayList<PageData>();
// Africa (Here should add country Header)
data.add(new PageData(R.drawable.ic_launcher, "Algeria"));
data.add(new PageData(R.drawable.ic_launcher, "Egypt"));
data.add(new PageData(R.drawable.ic_launcher, "Ethiopia"));
data.add(new PageData(R.drawable.ic_launcher, "Ghana"));
// Asia (Here should add country Header)
data.add(new PageData(R.drawable.ic_launcher, "Bangladesh"));
data.add(new PageData(R.drawable.ic_launcher, "India"));
data.add(new PageData(R.drawable.ic_launcher, "Pakistan"));
data.add(new PageData(R.drawable.ic_launcher, "Japan"));
// Europe (Here should add country Header)
data.add(new PageData(R.drawable.ic_launcher, "Belgium"));
data.add(new PageData(R.drawable.ic_launcher, "Finland"));
data.add(new PageData(R.drawable.ic_launcher, "Italy"));
data.add(new PageData(R.drawable.ic_launcher, "Poland"));
// America (Here should add country Header)
data.add(new PageData(R.drawable.ic_launcher, "Canada "));
data.add(new PageData(R.drawable.ic_launcher, "USA"));
data.add(new PageData(R.drawable.ic_launcher, "Mexico"));
data.add(new PageData(R.drawable.ic_launcher, "Bermuda"));
// Australia (Here should add country Header)
data.add(new PageData(R.drawable.ic_launcher, "Australia"));
data.add(new PageData(R.drawable.ic_launcher, "Fiji"));
data.add(new PageData(R.drawable.ic_launcher, "New Zealand"));
data.add(new PageData(R.drawable.ic_launcher, "Papua New Guinea"));
final ListView lv = (ListView) findViewById(R.id.list_view);
final ListViewAdapter lva = new ListViewAdapter(this, R.layout.listview_item, data);
lv.setAdapter(lva);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
PageData pd = data.get(position);
Toast.makeText(MainActivity.this.getBaseContext(), pd.getTitle(), Toast.LENGTH_SHORT).show();
}
});
}
}