Android Studio, Using Two Spinner (dropdown box) Select click Submit button open new activity page.
Give your Submit button an id.
android:id="#+id/submit" >>>In your xml file.
Create a variable before onCreate functions. >>>>In your java file.
public class Acces_Database extends AppCompatActivity {
Button buttonSub;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_acces__database);
buttonSub = (Button)findViewByid(R.id.submit);
buttonSub.setOnClickListener(new View.setOnClickListsener() {
#Override
public void onClick(View view){
startActivity(new Intent(Your_CurrentActivity_name.this,Your_NextActiivty_name.class));
}
});
Hope i answered your question ,if any irrelevancy ,please let me know.
Happy Coding!
Related
this is my first post here. I used the search function and could not find a complete answer,so I hope this is not a redundant question.
I should note that I m really new to coding so maybe I did find an answer but did not realise it.
I have been asked in class to find two different ways to fill the argument in the code below.
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(this);
}
#Override
public void onClick(View v) {
Toast.makeText(???,"Clicked!", Toast.LENGTH_LONG).show();
the first way i suppose would be toast.makeText(MainActivity.this.getActivity(),....).show();
the second one?
Use the MainActivity context.
Toast.makeText(MainActivity.this,"Clicked!", Toast.LENGTH_LONG).show();
v.getContext() and this both can be used
I'm new at developing app,I'm trying to develop app that make the users read with the voice thier emails so I want to add control bar that make them stop,slow or speed the reading
now i just want to know how to add button that appear with the user open his mail inbox
when I try this in usual way the button does not appear
public class Test1MainActivity extends AppCompatActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test1_main);
button=(Button) findViewById(R.id.button);
Intent intent=Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_EMAIL);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
How can I make the button appear with the mail inbox ? I mean like a tool for the users in their inbox.
So far, you are launching the intent when your activity starts.
You should create a Listener with the intent code and set it to your button like this:
public class Test1MainActivity extends AppCompatActivity {
private Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test1_main);
button=(Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent=Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_EMAIL);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
}
}
Check your button properties in layout Design
i am trying to implement ShineButton in my project . I have successfully synced the library to the gradle and added shine button in the xml.
now when i am trying to write the java code
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1 = (Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Kill bill", Toast.LENGTH_SHORT).show();
}
});
ShineButton shineButton = (ShineButton) findViewById(R.id.po_image2);
shineButton.init(context);
}
}
.init(activity); is showing cannot resolve symbol activity.
You don't literally copy the code verbatim, you read the documentation and object types supported by the method.
public void init(Activity activity) {
For example, I assume you are running that from an activity based on the usage of findViewById? Then you need "this instance of the Activity"
shineButton.init(this);
or an instance of an Activity if you were in a Fragment
shineButton.init(getActivity());
If the code is in Activity use shineButton.init(Activityname.this).
If it is in
fragment use shineButton.init(getActivity()).
Read this: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/ and this https://developer.android.com/training/index.html
Change:
shineButton.init(context);
To:
shineButton.init(MainActivity.this);
MainActivity.this holds the instance of MainActivity class and can be used to initialise the view.
I am creating a charity app for Android. The app consists of 4 pages, each with a button which, when clicked, should navigate the user to the next page.
-Currently using Eclipse SDK-
The first (welcome) page button works and the code for this is:
public class CharityAppActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button main = (Button) findViewById(R.id.mybutton);
main.setOnClickListener (new OnClickListener(){
#Override
public void onClick(View v) {
setContentView(R.layout.donate);
// TODO Auto-generated method stub
}
});
}
I am wondering where I should put the code for the other buttons?
(this java file is currently called CharityAppActivity.java)....
Any help would be gratefully received. I would be more than willing to offer you any more code if you need it to help me a little better
Ps. the pages are named main.xml, donate.xml, value.xml and thanks.xml
Activity is only one screen of application.
You should create more activities for every screen and do not try to only change content. It is not possible call setContentView() multiple times by default.
I suggest you try to more samples application from SDK directly, read some tutorials or book.
Like you are finding Button main = (Button) findViewById(R.id.mybutton);
find other buttons from your main activity and set their onClickHandler to invoke your different activities.
I am assuming all the four concerned buttons are in same layout.
You just need to create 4 Activities.
The OnClick method will call the next Activity using "startActivity"
#Override
public void onClick(View v) {
Intent it = new Intent(NextClass.class);
startActivity(it);
}
I am new to programming.
I'm creating a simple app which will handle my Button click event.
I have added the button using xml and linked it to the program, but the app force closes immediately after I run it.
Here is the code:
public class Sparkling extends Activity implements OnClickListener
{
Button b;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b=(Button)findViewById(R.id.Button1);
b.setOnClickListener(this);
}
#Override
public void onClick(View v)
{
//actions....
}
}
Without having any stack trace info, my guess would be Button1 is missing from or is misspelled on main.xml or something is wrong with your manifest file.
I found out what had happened.
I was using:
android:name="#+id/Button1"
instead of:
android:id="#+id/Button1"