Calling different layers from the same class

Posted by khalid on Stack Overflow See other posts from Stack Overflow or by khalid
Published on 2010-05-20T03:39:58Z Indexed on 2010/05/20 4:00 UTC
Read the original article Hit count: 350

Filed under:
|
|
|

Hi, I am here to seek some help with my code which i am facing a dead end road with. I'm trying to pass values from screen1.java using Intent to screen2.java. Passing the values is fine and I managed to get through it; however, when I check using if statement the program crash down. Here are my files, plzzzzzzzzzzz help

screen1.java package test.android; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button;

public class screen1 extends Activity { static String strKey = "Hello"; static final String strValue = "Hello";

public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.screen1);

//** button A      
  Button A = (Button) findViewById(R.id.btnClickA);
  A.setOnClickListener(new View.OnClickListener() {
     public void onClick(View arg0) {
     Intent i = new Intent(screen1.this, screen2.class);
     strKey = "NAME";
     i.setClassName("packageName", "packageName.IntentClass");
     String term = "Hello";
     i.putExtra("packageName.term", term);

     //i.putExtra(strKey, strValue);
     startActivity(i);
     }
  });
  //**
//** button B      
  Button B = (Button) findViewById(R.id.btnClickB);
  B.setOnClickListener(new View.OnClickListener() {
     public void onClick(View arg0) {
     Intent i = new Intent(screen1.this, screen3.class);
     startActivity(i);
     }
  });
  //**

} }

screen2.java package test.android; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button;

public class screen2 extends Activity { public void onCreate(Bundle icicle) { Bundle extras = getIntent().getExtras(); String term = extras.getString("packageName.term");

    System.out.println("--- Name  is  -->"+ term);

  if(term.equalsIgnoreCase("Hello") || term.equalsIgnoreCase("Name")){
      super.onCreate(icicle);
      setContentView(R.layout.screen3);
      Button b = (Button) findViewById(R.id.btnClick3);
      b.setOnClickListener(new View.OnClickListener() {
         public void onClick(View arg0) {
         setResult(RESULT_OK);
         finish();
         }
      });
  } else {
   super.onCreate(icicle);
   setContentView(R.layout.screen2);
   Button b = (Button) findViewById(R.id.btnClick2);
   b.setOnClickListener(new View.OnClickListener() {
      public void onClick(View arg0) {
      setResult(RESULT_OK);
      finish();
      }
   });

} // DOES NOT WORK !!!!!!!!! System.out.println("--- Name is -->"+ term);

} }

Layouts: screen1.xml

screen2.xml

screen3.xml

>

AndroidManifest.xml

  <activity android:name="screen1"
                    android:label="SCREEN 1">

     <intent-filter>
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>

  </activity>
  <activity android:name="screen2"
                    android:label="SCREEN 2">
  </activity>

  <activity android:name="screen3"
                    android:label="SCREEN 3">
  </activity>  

===== The error is caused by these lines of code in screen2.java: if(term.equalsIgnoreCase("Hello") || term.equalsIgnoreCase("Name")){ super.onCreate(icicle); setContentView(R.layout.screen3); Button b = (Button) findViewById(R.id.btnClick3); b.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { setResult(RESULT_OK); finish(); } }); } else { super.onCreate(icicle); setContentView(R.layout.screen2); Button b = (Button) findViewById(R.id.btnClick2); b.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { setResult(RESULT_OK); finish(); } }); }

**notice if I get rid of the entire IF statement and go with only the ELSE the program works fine.

© Stack Overflow or respective owner

Related posts about android

Related posts about java