Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.superlinux.generalengineeringfree;
- import java.util.HashMap;
- import java.util.Map;
- import android.R.integer;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- public class GeometryTableOfContents extends Activity {
- /*
- * Activity with a listing of Geometry shapes to get Area and Volume
- * currently we have: 1- Circle 2- Rectangle 3- Triangle 4-
- * This activity has ImageButtons whose view Ids are listed below in the variable table_of_contentsMap
- * Clicking an ImageButton takes you to the corresponding Android Activity.
- */
- OnClickListener listener;
- public GeometryTableOfContents() {
- // TODO Auto-generated constructor stub
- }
- Map <Integer,Class> table_of_contentsMap= new HashMap<Integer, Class>();
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.geometry_table_of_contents);
- //table of contents classes. ImageButton view Id vs destination Activity
- //E.g. GeometryRectangle.class represents an Android Activity class
- table_of_contentsMap.put(R.id.geometry_rectangle_imgbutton, GeometryRectangle.class);
- table_of_contentsMap.put(R.id.geometry_triangle_imgbutton, GeometryTriangle.class);
- table_of_contentsMap.put(R.id.geometry_circle_imgbutton, GeometryCircle.class);
- table_of_contentsMap.put(R.id.geometry_tarpizoid_imgbutton, GeometryTrapizoid.class);
- table_of_contentsMap.put(R.id.geometry_sphere_imgbutton, GeometrySphere.class);
- table_of_contentsMap.put(R.id.geometry_rectangular_solid_imgbutton, GeometryRectangularSolid.class);
- table_of_contentsMap.put(R.id.geometry_cone_imgbutton, GeometryCone.class);
- table_of_contentsMap.put(R.id.geometry_pyramid_imgbutton, GeometryPyramid.class);
- table_of_contentsMap.put(R.id.geometry_prism_imgbutton, GeometryPrism.class);
- listener=new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- if (!table_of_contentsMap.containsKey(v.getId())) return; //just in case, not to crash.
- Intent intent = new Intent(GeometryTableOfContents.this, table_of_contentsMap.get(v.getId()));
- startActivity(intent);
- }
- };
- for (int view_id : table_of_contentsMap.keySet()) findViewById(view_id).setOnClickListener(listener);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement