Hey guys,
I decided to try my hand at android programming. I have limited experience in C++, HTML, and javascript.
I am basically making a "hello world" app that takes two numbers and adds them together when a button is pressed. In the future this app will be converted to calculate the least common multiple and greatest common divisor. It will also have three tabs with one being the calculater, one being an explanation of how to do the work, and one being an "about" page.
Thats going to be a long way off and this is my getting to know android project and it will evolve as I learn more.
currently I can run the app on the virtual machine in eclipse. but when I press the "calculate button the app closes. I cant figure out where I went wrong so any help will be appreciated. (or point me to someone who can).
This is my .java file
and this is my XML file
I decided to try my hand at android programming. I have limited experience in C++, HTML, and javascript.
I am basically making a "hello world" app that takes two numbers and adds them together when a button is pressed. In the future this app will be converted to calculate the least common multiple and greatest common divisor. It will also have three tabs with one being the calculater, one being an explanation of how to do the work, and one being an "about" page.
Thats going to be a long way off and this is my getting to know android project and it will evolve as I learn more.
currently I can run the app on the virtual machine in eclipse. but when I press the "calculate button the app closes. I cant figure out where I went wrong so any help will be appreciated. (or point me to someone who can).
This is my .java file
Code:
package least.common.multiple;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class Main extends Activity {
int numberThree = 0;
int numberOne = 0;
int numberTwo = 0;
EditText tt;
EditText editnumberOne;
EditText editnumberTwo;
TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void button(View view) {
//do something in response to the button
try {
numberOne = Integer.parseInt(editnumberOne.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
try {
numberTwo = Integer.parseInt(editnumberTwo.getText().toString());
} catch(NumberFormatException nfa) {
System.out.println("Could not parse " + nfa);
}
numberThree = numberOne + numberTwo;
textView.setText(String.valueOf(numberThree));
}
}
and this is my XML file
Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical" >
<EditText
android:id= "@+id/editnumberOne"
android:layout_width="156dp"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/number_one"
android:inputType="number" >
<requestFocus />
</EditText>
<EditText
android:id= "@+id/editnumberTwo"
android:layout_width="156dp"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/number_two"
android:inputType="number" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="button"
android:text="@string/button_send" />
<TextView
android:id="@+id/textView"
android:layout_width="156dp"
android:layout_height="20dp"
android:layout_gravity="center" />
</LinearLayout>