package com.elegos.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class ListViewTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView myText = (TextView)findViewById(R.id.myTextView);
Button nextButton = (Button)findViewById(R.id.ButtonNext);
nextButton.setOnClickListener(new Button.OnClickListener() {
public void onClick (View v){
Intent nextIntent=new Intent
(ListViewTes.this,ExmpActivity.class);
startActivity(nextIntent);
});
}}
U will create another activity by name ExmpActivity as follows
package com.elegos.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class ExmpActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xyz);
Button backButton = (Button)findViewById(R.id.ButtonBack);
backButton.setOnClickListener(new Button.OnClickListener() {
public void onClick (View v){
Intent backIntent=new Intent
(ExmpActivity.this,ListViewTes.class);
startActivity(backIntent);
});
}
}
On Jul 22, 2:27 pm, elegos <[email protected]> wrote:
> Hello there!
>
> I'm a newbie in Android programming, and was exploring the possibility
> to switch between more than - one - layouts (i.e. more pages?).
>
> So I've created a new XML layout page (called second.xml) and created
> some things in there. At least I've created a button to switch back to
> the first layout, but a NullPointerException fires up when the
> application starts, and that only for the "back" button, while the
> "next" button just works great.
>
> Any suggestion?
> Thanks :)
>
> package com.elegos.test;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.view.View;
> import android.view.View.OnClickListener;
> import android.widget.Button;
> import android.widget.TextView;
>
> public class ListViewTest extends Activity {
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
>
> TextView myText = (TextView)findViewById(R.id.myTextView);
>
> Button nextButton = (Button)findViewById(R.id.ButtonNext);
> Button backButton = (Button)findViewById(R.id.ButtonBack);
>
> nextButton.setOnClickListener(getCListener(R.layout.second));
> try {backButton.setOnClickListener(getCListener
> (R.layout.main));} catch(Exception e) {myText.append("\n"+e.toString
> ());}
> }
>
> final private OnClickListener getCListener(final int layout) {
> return new Button.OnClickListener() {
> public void onClick(View v) {
> setContentView(layout);
> }
> };
> }
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---