Android codes Creating next Button



Creating a NEXT Button
This is the code for MainActivity.java
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
       Button next; // we are declaring the button

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);//  this calls for the intent
next=(Button)findViewById(R.id.but1); // this calls for the id of the button
next.setOnClickListener(new View.OnClickListener() {// here we are setting the listener
@Override
public void onClick(View view) //here we are creating a method for the events  
{
                           

//                  Intent myIntent = new Intent(MainActivity.this, NextClass.class);
//                                       startActivity(myIntent); 
                     // either you can use the code above or you use that below
                                        
                                        
Intent x= new Intent(getApplicationContext(),NextIntent.class);// we are creating the object for our class
startActivity(x);
}

});
                    
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}
The code ends above
Note: For every Intent you create should have a java class


The code bellow calls for  nextIntent .java
import android.app.Activity;
import android.os.Bundle;

public class NextIntent extends Activity {
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.nextintent); // here we are calling for the intent
}

}
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

2 comments: