how can I make the button appear - android

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

Related

Android Using Two Spinner Select click Submit button open new activity

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!

Dynamically Add button from one activity to another

i am working on an app in which, button Onclick dynamically created a button from one activity and button is appeared in another activity.
So, for your button, see the code below. I'm just using SharedPreferences for testing if button has been clicked before or not.
// Inside your onCreate() method of your SecondActivity.java
((Button)findViewById(R.id.activity2_button)).setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
getSharedPreferences("SharedPreferences", Context.MODE_PRIVATE).edit().putBoolean("ShowButton", true).commit(); // put Boolean inside SharedPreferences
Intent main = new Intent(this, FirstActivity.class);
main.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(main);
finish();
}
}
And now, the FirstActivity.java code :
public class FirstActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1_layout);
if (getSharedPreferences("SharedPreferences", Context.MODE_PRIVATE).getBoolean("ShowButton", false))
((Button)findViewById(R.id.activity1_button)).setVisibility(View.VISIBLE);
else
((Button)findViewById(R.id.activity1_button)).setVisibility(View.GONE);
}
}
Test it, and tell me if this works great. Hope it will work for you, Darkball60 :)

Android inter-activity communication

Hi I am a total android newbie so my question might seem dumb.
I want to make a program that has two activities, one of them is TinyCalActivity1 and the other is TinyCalActivity2.
My intention was that I can make a button to switch between this activity,
package my.app.tinyCal;
public class TinyCalActivity1 extends Activity {
/** Called when the activity is first created. */
Button myButton;
EditText myEdit;
//Intent i = new Intent(TinyCalActivity1.this, TinyCalActivity2.class);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton = (Button)findViewById(R.id.Next);
myEdit = (EditText)findViewById(R.id.entry);
CharSequence thisNum = "1234565";
myEdit.setText(thisNum);
OnClickListener myListener = new OnClickListener(){
public void onClick(View v){
}
};
myButton.setOnClickListener(myListener);
}
}
and TinyCalActivity2.
However, when I write this line and run in my android AVD, it tells me that there's an error.
Intent i = new Intent(this, TinyCalActivity2.class);
There is no error hint in eclipse and I do not know why.
I create TinyCalActivity2.java as a separate file in the same folder as my TinyCalActivity1.java file. And I have registered TinyCalActivity2 in my AndroidManifest.xml.
I would really appreciate any help!
If you put your code
Intent i = new Intent(this, TinyCalActivity2.class);
in button click event, then this refers to button and not ACTIVITY. Thus, you need to mention it as
Intent i = new Intent(TinyCalActivity1.this, TinyCalActivity2.class);
This may resolve the issue
You can try this way.
myButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Intent i = new Intent(this, TinyCalActivity2.class);
finish();
}
};

Force Close when i run this application

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"

Android: Button action not being called

I'm trying to make an app where you start at a menu, click a button and are brought to a list of items (which I later hope to make clickable). But I can't seem to make it call my next activity. Can anyone help?
Your main class / activity:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Menu Button
Button startNewActivity = (Button)findViewById(R.id.startnew);
startNewActivity.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent newActivityIntent = new Intent(YOUR-CLASS-NAME.this,NewActivity.class);
startActivity(newActivityIntent);
}
});
Your NewActivity Class:
public class NewActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new);
}
}
Is the question "How do I call the next activity" ?
If so, it's pretty easy - Assuming the Activity you want to call is "SomeActivity", call this:
Intent someActivity = new Intent(getBaseContext(), SomeActivity.class);
startActivity(someActivity);
There's also a "startActivityForResult" method, if you want data back from the Activity you're calling. For reference, the Activity page of the API Documentation can be found here. Good luck!

Categories

Resources