Phone Orientation[found answer]

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Phone Orientation[found answer]

Postby UndeniablyRexer » Wed Jul 29, 2009 11:37 pm

I've searched the forums, but I couldn't find this anywhere despite the question seeming noobish.

So I have this program that has tiers of pages. Everything works fine, but when I slide the phone open, it starts the program over again.

I assume something is wrong with my onCreate function, I just don't know what it is.

Thank for any help.

Edit: apparently I failed at looking before, I put "android:configChanges="orientation|keyboardHidden" in the manifest and it works now.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class PhysicsFusion extends Activity {
  2.  
  3.     /** Called when the activity is first created. */
  4.  
  5.     @Override
  6.  
  7.     public void onCreate(Bundle savedInstanceState) {
  8.  
  9.         super.onCreate(savedInstanceState);
  10.  
  11.         rootMenu();
  12.  
  13.     }
  14.  
  15.     //first tier
  16.  
  17.     public void rootMenu() {
  18.  
  19.         setContentView(R.layout.main);
  20.  
  21.        
  22.  
  23.         final Button physics = (Button) findViewById(R.id.physics);
  24.  
  25.         final Button chemistry = (Button) findViewById(R.id.chemistry);
  26.  
  27.         final Button genMath = (Button) findViewById(R.id.math);
  28.  
  29.        
  30.  
  31.         physics.setOnClickListener(new OnClickListener() {
  32.  
  33.                  @Override
  34.  
  35.                  public void onClick(View v) {
  36.  
  37.                          physics();
  38.  
  39.                  }
  40.  
  41.         });
  42.  
  43.         chemistry.setOnClickListener(new OnClickListener() {
  44.  
  45.                  @Override
  46.  
  47.                  public void onClick(View v) {
  48.  
  49.                          chemistry();
  50.  
  51.                  }
  52.  
  53.         });
  54.  
  55.         genMath.setOnClickListener(new OnClickListener() {
  56.  
  57.                  @Override
  58.  
  59.                  public void onClick(View v) {
  60.  
  61.                          genMath();
  62.  
  63.                  }
  64.  
  65.         });
  66.  
  67.     }
  68.  
  69.     //second tier
  70.  
  71.     public void physics() {
  72.  
  73.         setContentView(R.layout.physics);
  74.  
  75.        
  76.  
  77.         final Button statics = (Button) findViewById(R.id.statics);
  78.  
  79.         final Button em = (Button) findViewById(R.id.em);
  80.  
  81.         final Button mechanics = (Button) findViewById(R.id.mechanics);
  82.  
  83.        
  84.  
  85.         statics.setOnClickListener(new OnClickListener() {
  86.  
  87.                  @Override
  88.  
  89.                  public void onClick(View v) {
  90.  
  91.                          statics();
  92.  
  93.                  }
  94.  
  95.         });
  96.  
  97.         em.setOnClickListener(new OnClickListener() {
  98.  
  99.                  @Override
  100.  
  101.                  public void onClick(View v) {
  102.  
  103.                          em();
  104.  
  105.                  }
  106.  
  107.         });
  108.  
  109.         mechanics.setOnClickListener(new OnClickListener() {
  110.  
  111.                  @Override
  112.  
  113.                  public void onClick(View v) {
  114.  
  115.                          mechanics();
  116.  
  117.                  }
  118.  
  119.         });
  120.  
  121.     }
  122.  
  123.     public void chemistry() {
  124.  
  125.     }
  126.  
  127.     public void genMath() {
  128.  
  129.     }
  130.  
  131.     //third tier
  132.  
  133.     //physics
  134.  
  135.     protected ListView forcesList;
  136.  
  137.     protected ArrayList<Force> forces = new ArrayList<Force>();
  138.  
  139.     public void statics() {
  140.  
  141.         setContentView(R.layout.statics);
  142.  
  143.  
  144.  
  145.         final EditText force = (EditText) findViewById(R.id.staticsForce);
  146.  
  147.         final EditText angle = (EditText) findViewById(R.id.staticsAngle);
  148.  
  149.         final Button add = (Button) findViewById(R.id.staticsAdd);
  150.  
  151.         this.forcesList = (ListView) this.findViewById(R.id.forcesList);
  152.  
  153.         final Button compute = (Button) findViewById(R.id.staticsCompute);
  154.  
  155.        
  156.  
  157.         add.setOnClickListener(new OnClickListener() {
  158.  
  159.                 @Override
  160.  
  161.                 public void onClick(View v) {
  162.  
  163.                         float temp1 = Float.parseFloat(force.getText().toString());
  164.  
  165.                         float temp2 = Float.parseFloat(angle.getText().toString());
  166.  
  167.                         forces.add(new Force(temp1, temp2));
  168.  
  169.                         refreshForceList();
  170.  
  171.                         force.setText("");
  172.  
  173.                         angle.setText("");
  174.  
  175.                 }
  176.  
  177.         });
  178.  
  179.     }
  180.  
  181.         private void refreshForceList() {
  182.  
  183.                 forcesList.setAdapter(new ArrayAdapter<Force>(this, android.R.layout.simple_list_item_1, forces));
  184.  
  185.         }
  186.  
  187.  
  188.  
  189.     public void em() {
  190.  
  191.     }
  192.  
  193.     public void mechanics() {
  194.  
  195.     }
  196.  
  197. }
Parsed in 0.043 seconds, using GeSHi 1.0.8.4
UndeniablyRexer
Freshman
Freshman
 
Posts: 7
Joined: Fri Jun 12, 2009 1:40 am

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests