1. Check out our companion app, Forums for Android! Download from Google Play

How to go to new screen ..

Discussion in 'Application Development' started by macbeth4397, Nov 19, 2010.

  1. macbeth4397

    macbeth4397 New Member
    Thread Starter
    5

    Nov 19, 2010
    1
    0
    5
    I am new to android development programming. So i started few weeks ago and i am stuck in a trouble.. I am trying to make a simple program which have two screen ..the first screen (main.xml) have two bottun and one text view and one edit text when some one input their name in the edit text and click the first button (ButtonClick) it shows hello there and the name inputed form edit text. then when cock the second button (ButtonOk) it goes to second screen showing a message "successful" in a text view.. but when i click the ButtonOk nothing happens... can any one help.. my coded are below:

    The main java class:

    package com.example.helloshamik;

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;

    public class hellothere extends Activity {
    Button ButtonClick, ButtonOk;
    TextView TextShow, TextFinal;
    EditText Name;
    /** Called when the activity is first created. */
    @Override

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ButtonClick = (Button)findViewById(R.id.ButtonClick);
    ButtonOk = (Button)findViewById(R.id.ButtonOk);
    TextShow = (TextView)findViewById(R.id.TextShow);
    TextFinal = (TextView)findViewById(R.id.TextFinal);
    Name = (EditText) findViewById(R.id.Name);

    //Initialize textview

    TextShow.setText("Click the 'Click it' Botton");

    ButtonClick.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
    TextFinal.setText("Hello There "+ Name.getText());
    }
    });
    ButtonOk.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
    Intent myIntent = new Intent(v.getContext(), screen1.class);
    startActivityForResult(myIntent, 0);
    }
    });

    }
    }

    the second java class:


    package com.example.helloshamik;

    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.TextView;

    public class screen1 extends Activity {
    TextView TextSucess;
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextSucess = (TextView)findViewById(R.id.TextSuccess);
    TextSucess.setText("Sucessful");
    }
    }

    FYI I have added activity in mainfest.xml and done other stuff too..
     

    Advertisement

  2. UniversalMind88

    UniversalMind88 New Member
    5

    Nov 21, 2010
    1
    0
    5
    try with this example:


    Code (Text):
    1.  
    2. public class one extends Activity
    3. {
    4.       Button goTO;
    5.  
    6.      public void onCreate(Bundle savedInstanceState)
    7.      {
    8.          super.onCreate(savedInstanceState);
    9.          setContentView(R.layout.layONE);
    10.          
    11.          goTO = (Button)this.findViewById(R.id.buttongoTO);
    12.          goTO.setOnClickListener(new View.OnClickListener(){
    13.             public void onClick(View v)
    14.             {
    15.                 Intent i = new Intent(one.this, secondCLASS.class);
    16.                 startActivity(i);
    17.             }
    18.         });
    19. }
    20.  
    I hope to give u a hand! XD
    (sorry for my bad english)
     

Share This Page

Loading...