I want to create a clock showing the hour and Minute of the current time like this 02:15 PM. What i want is now to keep the minutes part updating obviously after every 60 seconds as it is changed in our systems. So i want to know what is the best way to keep the time updating
thanks
.xml file's code,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
<TextView
android:id="#+id/txtTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world" />
</RelativeLayout>
Activity file's code,
package com.example.demoproject;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.text.format.Time;
import android.widget.TextView;
public class MainActivity extends Activity
{
private static TextView textview;
private Timer timer;
private Time today;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview = (TextView ) findViewById( R.id.txtTime );
today = new Time(Time.getCurrentTimezone());
timer = new Timer();
timer.schedule(new RemindTask(), 1000, 1000 );
}
private class RemindTask extends TimerTask
{
public void run()
{
runOnUiThread(new Runnable()
{
public void run()
{
today.setToNow();
textview.setText(today.format("%k:%M:%S")); // Current time
}
});
}
}
}
Related
I'm trying to make a simple number guessing game in android. A random number is generated when the app in launched and the user has to guess the number. The result is displayed in the form of a long toast. But when I run the app and try and enter a number the emulator says: "unfortunately High Low Game has stopped working". I have tried resetting the app and also clearing data from my emulators settings menu but it didn't make a difference. I sense something is wrong with my java code but haven't been able to figure out what is the problem so far.
Here is the java code:
package com.example.pooria.hilowgame;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.Random;
import android.widget.EditText;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
int randomNum;
public void buttonClicked(View view){
EditText numField=(EditText) findViewById(R.id.numField);
int numFieldVal= Integer.parseInt(numField.toString());
String toastMessage= "";
if(numFieldVal>randomNum){
toastMessage= "Higher";
}else if(numFieldVal==randomNum){
toastMessage= "You made the right guess!!!";
}else{
toastMessage= "Lower";
}
Toast.makeText(getApplicationContext(),toastMessage,Toast.LENGTH_LONG).show();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Random randomGenerator= new Random();
int randomNum= randomGenerator.nextInt(101);
}
}
and the xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.pooria.hilowgame.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Guess the random number"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp"
android:gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Guess!!!"
android:id="#+id/button"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:onClick="buttonClicked" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/numField"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp" />
</RelativeLayout>
Thanks
package com.example.pooria.hilowgame;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.Random;
import android.widget.EditText;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
int randomNum; <--------
public void buttonClicked(View view){
EditText numField=(EditText) findViewById(R.id.numField);
int numFieldVal= Integer.parseInt(numField.getText().toString()); <-------
String toastMessage= "";
if(numFieldVal>randomNum){
toastMessage= "Higher";
}else if(numFieldVal==randomNum){
toastMessage= "You made the right guess!!!";
}else{
toastMessage= "Lower";
}
Toast.makeText(getApplicationContext(),toastMessage,Toast.LENGTH_LONG).show();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Random randomGenerator= new Random();
randomNum = randomGenerator.nextInt(101); <--------
}
}
See the marked lines. Code is changed to the correct, but I added text to explain what is wrong.
Change
int numFieldVal= Integer.parseInt(numField.toString());
to
int numFieldVal= Integer.parseInt(numField.getText().toString());
The unchanged line is the cause of the crash.
And for a game related problem:
This line:
int randomNum = randomGenerator.nextInt(101);
is wrong. You create a new local variable, meaning the global randomNum is 0 - always. The solution is simple - remove the int, so it references the main randomNum variable.
And by doing that, you have solved unwanted results and solved the crash.
Hi can anyone help me on my small project please, I have been following this Tutorial and I got to the part where I insert 1 Minute into the EditText the Progress Bar works fine 1 Progress per sec but when I put in more than 1 Minute into the EditText the Progress Bar does not work. It does not goes down please help?
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#086A87">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp" >
<EditText
android:id="#+id/edtTimerValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="minutes"
android:inputType="phone" />
<Button
android:id="#+id/btnStartTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="2"
android:gravity="center"
android:text="Start Timer"
android:background="#drawable/custombuttongreen"
android:textColor="#fff"/>
<Button
android:id="#+id/btnStopTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="2"
android:gravity="center"
android:text="Stop Timer"
android:visibility="gone"
android:background="#drawable/custombuttongreen"
android:textColor="#fff"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="350dip"
android:layout_height="350dip"
android:indeterminate="false"
android:progressDrawable="#drawable/circle"
android:background="#drawable/circle_shape"
style="?android:attr/progressBarStyleHorizontal"
android:max="60"
android:progress="0" />
<TextView
android:id="#+id/tvTimeCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="00:00"
android:textColor="#fff"
android:textSize="60dip"/>
</RelativeLayout>
MainActivity.java
package com.tag.countdowntimer;
import com.tag.countdowntimer.R.drawable;
import android.R.color;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
int i=-1;
ProgressBar mProgressBar;
private Button buttonStartTime, buttonStopTime;
private EditText edtTimerValue;
private TextView textViewShowTime; // will show the time
private CountDownTimer countDownTimer; // built in android class
// CountDownTimer
private long totalTimeCountInMilliseconds; // total count down time in
// milliseconds
private long timeBlinkInMilliseconds; // start time of start blinking
private boolean blink; // controls the blinking .. on and off
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
buttonStartTime = (Button) findViewById(R.id.btnStartTime);
buttonStopTime = (Button) findViewById(R.id.btnStopTime);
textViewShowTime = (TextView) findViewById(R.id.tvTimeCount);
edtTimerValue = (EditText) findViewById(R.id.edtTimerValue);
buttonStartTime.setOnClickListener(this);
buttonStopTime.setOnClickListener(this);
mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
}
#Override
public void onClick(View v) {
if (v.getId() == R.id.btnStartTime) {
textViewShowTime.setTextAppearance(getApplicationContext(),
R.style.normalText);
setTimer();
//Hides the Keyboard
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edtTimerValue.getWindowToken(), 0);
buttonStopTime.setVisibility(View.VISIBLE);
buttonStartTime.setVisibility(View.GONE);
edtTimerValue.setVisibility(View.GONE);
edtTimerValue.setText("");
//textViewShowTime.setTextColor(color.white);
//textViewShowTime.getContext();
startTimer();
} else if (v.getId() == R.id.btnStopTime) {
countDownTimer.cancel();
buttonStartTime.setVisibility(View.VISIBLE);
buttonStopTime.setVisibility(View.GONE);
edtTimerValue.setVisibility(View.VISIBLE);
}
}
private void setTimer() {
int time = 0;
if (!edtTimerValue.getText().toString().equals("")) {
time = Integer.parseInt(edtTimerValue.getText().toString());
} else
Toast.makeText(MainActivity.this, "Please Enter Minutes...",
Toast.LENGTH_LONG).show();
totalTimeCountInMilliseconds = 60 * time * 1000;
timeBlinkInMilliseconds = 30 * 1000;
}
private void startTimer() {
countDownTimer = new CountDownTimer(totalTimeCountInMilliseconds, 500) {
// 500 means, onTick function will be called at every 500
// milliseconds
#Override
public void onTick(long leftTimeInMilliseconds) {
long seconds = leftTimeInMilliseconds / 1000;
//i++;
//Setting the Progress Bar to decrease wih the timer
mProgressBar.setProgress((int) (leftTimeInMilliseconds / 1000));
textViewShowTime.setTextAppearance(getApplicationContext(),
R.style.normalColor);
if (leftTimeInMilliseconds < timeBlinkInMilliseconds) {
textViewShowTime.setTextAppearance(getApplicationContext(),
R.style.blinkText);
// change the style of the textview .. giving a red
// alert style
if (blink) {
textViewShowTime.setVisibility(View.VISIBLE);
// if blink is true, textview will be visible
} else {
textViewShowTime.setVisibility(View.INVISIBLE);
}
blink = !blink; // toggle the value of blink
}
textViewShowTime.setText(String.format("%02d", seconds / 60)
+ ":" + String.format("%02d", seconds % 60));
// format the textview to show the easily readable format
}
#Override
public void onFinish() {
// this function will be called when the timecount is finished
textViewShowTime.setText("Time up!");
textViewShowTime.setVisibility(View.VISIBLE);
buttonStartTime.setVisibility(View.VISIBLE);
buttonStopTime.setVisibility(View.GONE);
edtTimerValue.setVisibility(View.VISIBLE);
}
}.start();
}
}
Normal State of Timer
When I enter 1 Minute
When I Entered 3 Minutes
Progress Bar is not Counting Down
In your main.xml, for ProgressBar you mentioned max value as 60. So the progress bar takes it max value as 60 and your progress bar starts decreasing from 60 seconds onwards.
Instead of that to work your Progress bar properly all times, in your "setTimer()" method write the below line.
mProgressBar.setMax(60*time);
I've only been working with Android for 2 weeks and I'm trying to create a simple homework assignment list to learn the basics. The code I have written displays information through an EditText and an ArrayList. When I go to one of my activities through my MainActivity and add information it shows up great. But when I go back to my MainActivity and back again to my previous activity. My data is deleted (or not displayed, I'm not sure). I'm sure I'm messing up something basic. If anyone is willing to offer some help or pointers, I'd greatly appreciate it. Thank You!
Here is my MainActivity Code:
package com.example.homeworkassignments;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
public class MainActivity extends Activity {
// instantiation of buttons
private Button btnDatabase;
//LIST OF ARRAY STRINGS WHICH WILL SERVE AS LIST ITEMS
ArrayList<String> listItems = new ArrayList<String>();
//DEFINING A STRING ADAPTER WHICH WILL HANDLE THE DATA OF THE LISTVIEW
ArrayAdapter<String> adapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
databaseButton();
} // end onCreate()
public void databaseButton() {
//create database button
btnDatabase = (Button)findViewById(R.id.databaseBtn);
btnDatabase.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//start Database class when identify button is clicked
Intent i = new Intent(MainActivity.this, Database.class);
startActivity(i);
}
});
} // end databaseButton()
Here is my Database Activity Class Code:
package com.example.homeworkassignments;
import java.util.ArrayList;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
public class Database extends ListActivity {
private Button addData;
private Button removeData;
private Button back;
//LIST OF ARRAY STRINGS WHICH WILL SERVE AS LIST ITEMS
ArrayList<String> listItems = new ArrayList<String>();
//DEFINING A STRING ADAPTER WHICH WILL HANDLE THE DATA OF THE LISTVIEW
ArrayAdapter<String> adapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_database);
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,listItems);
setListAdapter(adapter);
addButton();
removeButton();
backButton();
} // end OnCreate()
public void addButton() {
// create add button
addData = (Button)findViewById(R.id.databaseAddBtn);
addData.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView myEdit = (TextView)findViewById(R.id.editText1);
String myEditValue = myEdit.getText().toString();
listItems.add(myEditValue);
adapter.notifyDataSetChanged();
myEdit.setText("");
}
});
} // end addButton()
public void removeButton() {
// create remove Button
removeData = (Button)findViewById(R.id.databaseRemoveBtn);
removeData.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (listItems.isEmpty()) {
listItems.clear();
}
else {
listItems.remove(0);
}
adapter.notifyDataSetChanged();
}
});
}
public void backButton() {
// create back Button
back = (Button)findViewById(R.id.databaseBackBtn);
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Database.this, MainActivity.class);
startActivity(i);
}
});
} // end backButton()
} // end Database class
And finally, here is the XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >
<Button
android:id="#+id/databaseAddBtn"
style="?#android:style/ButtonBar"
android:layout_width="35dp"
android:layout_height="35dp"
android:text="#string/add_button" />
<Button
android:id="#+id/databaseRemoveBtn"
style="?#android:style/ButtonBar"
android:layout_width="35dp"
android:layout_height="35dp"
android:text="#string/remove_button" />
<Button
android:id="#+id/databaseBackBtn"
style="?#android:style/ButtonBar"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="#string/back" />
</LinearLayout>
<EditText android:id="#+id/editText1"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="35dp"
android:ems="10" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false" />
</LinearLayout>
I understand it's a lot and probably very poorly written, but any help or advice would be extremely appreciated (I'm just trying to learn Android!)
ok i think u want to keep the arraylist constant in Database.java...
there are 2 cases of storage i can guess :-
if u only want to store until you are executing the app and you allow the data be lost if the app is exited then in that case simply do this
a. Declare an ArrayList like this public ArrayList<String> listItems = new ArrayList<String>(); in MainActivity.java and remove the same from Database.java.
b. to add to this list you will access using MainActivity.listItems.add(object);
You can try using public static ArrayList<String> listItems = new ArrayList<String>();
instead in MainActivity note the "static" it can hold data even if u exited the app.For
more on static variables you can refer any tutorial.
it should store the data permanently so dat even if you reboot you will have the data.
if your case is this then u need to use database.
Hope it helps ....
thanks
I want to show continuous notifications in my application.
Currently I am able to raise notification automatically after 4sec but what I want is it should continuously raise after specific time interval.
Following is my code.
my xml file is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button android:id="#+id/notify"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Raise a notification"
android:onClick="notifyMe"
/>
<Button android:id="#+id/cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Clear the notification"
android:onClick="clearNotification"
/>
</LinearLayout>
this is my activity file
package com.vimaltuts.android.notificationexample;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class NotificationExampleActivity extends Activity {
private static final int NOTIFY_ME_ID=1987;
private int count=0;
private NotificationManager mgr=null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mgr=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Timer timer = new Timer();
timer.schedule(new TimerTask()
{
public void run()
{
View v = new View(getApplicationContext());
notifyMe(v);
}},4000);
}
#SuppressWarnings("deprecation")
public void notifyMe(View v)
{
#SuppressWarnings("deprecation")
Notification note=new Notification(R.drawable.stat_notify_chat,"Status message!",System.currentTimeMillis());
PendingIntent i=PendingIntent.getActivity(this,0,new Intent(this, NotificationMessage.class),0);
note.setLatestEventInfo(this, "New Email","Unread Conversation", i);
note.number=++count;
note.vibrate=new long[] {500L, 200L, 200L, 500L};
note.flags|=Notification.FLAG_AUTO_CANCEL;
mgr.notify(NOTIFY_ME_ID, note);
}
public void clearNotification(View v) {
mgr.cancel(NOTIFY_ME_ID);
}
}
Please tell me where should I need to have additional code if any?
Also is it possible with service..how?
i tried following code foe test purpose but it did't work...can anyone tell me where i goes wrong
following is my activity code
Intent i= new Intent(NotificationExampleActivity.this,NotificationService.class);
PendingIntent pi=PendingIntent.getService(NotificationExampleActivity.this, 0, i, 0);
AlarmManager alarmMgr=(AlarmManager)getSystemService(ALARM_SERVICE);
alarmMgr.cancel(pi);
alarmMgr.setRepeating(alarmMgr.ELAPSED_REALTIME_WAKEUP, System.currentTimeMillis(),(10*1000), pi);
Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();
And following is my broadcast reciver
Toast.makeText(context, "Repeating Alarm worked.", Toast.LENGTH_LONG).show();
i want to display msg="Repeating Alarm worked" after some time intervel
Try using an AlarmManager along with the notification.
You can set a repeating alarm in your Activity. Then create a class that extends the BroadcastReceiver. Override the onReceive method where in you can write the code for your notification.
A tutorial on this is explained very well over here.
When I launch the application and click the button to go to the Activity, I suddenly get a Force Close. I've tried to erase it all and write it again, but it is still there. What could be the problem?
package com.alexgascon.formuladora;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Matematicas extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
final Button BtnEcSegundoGrado = (Button)findViewById(R.id.ecsegundogrado);
final Button BtnFracciones = (Button)findViewById(R.id.fracciones);
final Button BtnMCD = (Button)findViewById(R.id.maximocomunBoton);
BtnMCD.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
Intent MCDintent = new Intent(Matematicas.this,Maximocomun.class);
startActivity(MCDintent);
}
});
}
}
And here is the layout code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/pizarramatesverde"
android:gravity="center" >
<Button
android:id="#+id/ecsegundogrado"
android:layout_height="wrap_content"
android:layout_width="265sp"
android:text="#string/ecsegundo"
android:textColor="#color/Negro"
/>
<Button
android:id="#+id/fracciones"
android:layout_height="wrap_content"
android:layout_width="265sp"
android:text="#string/fracciones"
android:layout_below="#id/ecsegundogrado"
android:textColor="#color/Negro"
/>
<Button
android:id="#+id/maximocomunBoton"
android:layout_height="wrap_content"
android:layout_width="265sp"
android:text="#string/maximocomun"
android:layout_below="#id/fracciones"
android:layout_marginBottom="80sp"
android:textColor="#color/Negro"
/>
</RelativeLayout>
You need to call setContentView before findViewById:
setContentView(R.layout.yourlayoutxmlname);
final Button BtnEcSegundoGrado = (Button)findViewById(R.id.ecsegundogrado);
final Button BtnFracciones = (Button)findViewById(R.id.fracciones);
final Button BtnMCD = (Button)findViewById(R.id.maximocomunBoton);
You need to call setContentView(R.layout.yourxmlLayout); to have the layout being referenced on your activity class.
Try to pop a toast from the click listener and see if it works. If it does - then the problem is in the activity that you want to launch.
You need to add the setContentView(R.layout.yourlayoutxmlname);.
Try the following code:
package com.alexgascon.formuladora;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Matematicas extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.yourlayoutxmlname);
final Button BtnEcSegundoGrado = (Button)findViewById(R.id.ecsegundogrado);
final Button BtnFracciones = (Button)findViewById(R.id.fracciones);
final Button BtnMCD = (Button)findViewById(R.id.maximocomunBoton);
BtnMCD.setOnClickListener( new OnClickListener(){
#Override
public void onClick(View arg0) {
Intent MCDintent = new Intent(Matematicas.this,Maximocomun.class);
startActivity(MCDintent);
}
});
}
}