I am having problems getting the integer values for a simple math program out of the edittext boxes. I can get a string out of it but when I try to convert it to a integer it crashes. I have tried:
int a = Intger.parseInt(X2.getText().toString());
and it still crashes. Any idea's would be greatly appreciated.
Here is source code.
package siu.edu.cs215;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class Quadratic extends Activity {
private TextView answer;
private EditText X2, X, K;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quad);
Button1 = (Button)findViewById(R.id.quad);
Button2 = (Button)findViewById(R.id.backwards);
answer = (TextView)findViewById(R.id.B1);
X2 = (EditText)findViewById(R.id.xsquared);
X = (EditText)findViewById(R.id.xcoeff);
K = (EditText)findViewById(R.id.kconst);
}
public Button Button1 = null;
public Button Button2 = null;
public void QA (View view){
//double sol1=0.0, sol2=0.0, disc=0.0;
int a = Integer.parseInt(X2.getText().toString());
//int b = Integer.getInteger(X.getText().toString());
//int c = Integer.getInteger(K.getText().toString());
//disc = Math.pow(b, 2) - 4.0*a*c;
//sol1 = (-b + Math.sqrt(disc)) / (2.0 * a);
//sol2 = (-b - Math.sqrt(disc)) / (2.0 * a);
answer.setText(a);
};
public void BACK (View view){
Intent i = new Intent(this, ExtraCreditActivity.class);
startActivity(i);
}
}
Here is the xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight=".6" >
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" >
<EditText
android:id="#+id/xsquared"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:inputType="number" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="X^2 +"
android:textSize="20dp" />
<EditText
android:id="#+id/xcoeff"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:gravity="center"
android:text="X + "
android:textSize="20dp" />
<EditText
android:id="#+id/kconst"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:inputType="number" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1.2" >
<Button
android:id="#+id/quad"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="QA"
android:text="Quadratic" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight=".8" >
<TextView
android:id="#+id/B1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2pt"
android:text="#string/app_name" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/backwards"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:onClick="BACK" />
</TableRow>
</TableLayout>
</LinearLayout>
Most likely you're problem is in trying to parse an empty string. Perhaps you can simply avoid performing any calculations unless all fields can be correctly parsed. Put your parsing into a try/catch block.
Related
I'm an Android beginner and I have a little problem.
I have 2 radioButtons titled "Yes" and "No", 4 editTexts which are disabled and a button titled "Reset All".
Now, when I select the "No" radioButton, editTexts 1 and 2 become enabled and 1 gains focus. This is the desired behaviour. But When I select "Reset All" and again repeat the procedure, only editText 2 gets enabled and the "No" radioButton is still unchecked.
Following is my code:
MainActivity.java
package com.example.chris.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
public class MainActivity extends AppCompatActivity {
EditText e1;
EditText e2;
EditText e3;
EditText e4;
RadioButton yes;
RadioButton no;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText)findViewById(R.id.e1);
e2 = (EditText)findViewById(R.id.e2);
e3 = (EditText)findViewById(R.id.e3);
e4 = (EditText)findViewById(R.id.e4);
yes = (RadioButton)findViewById(R.id.yes);
no = (RadioButton)findViewById(R.id.no);
}
public void onClickreset(View v){
yes.setChecked(false);
no.setChecked(false);
e1.setEnabled(false);
e2.setEnabled(false);
e3.setEnabled(false);
e1.setText("");
e2.setText("");
e3.setText("");
e4.setText("");
};
public void onRadioButtonClicked(View v)
{
boolean checked = ((RadioButton) v).isChecked();
switch(v.getId()){
case R.id.yes:
if(checked)
e1.setEnabled(false);
e2.setEnabled(false);
e3.setEnabled(true);
e3.requestFocus();
break;
case R.id.no:
if(checked)
e1.setEnabled(true);
e2.setEnabled(true);
e2.requestFocus();
e2.clearFocus();
e3.setEnabled(false);
break;
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.chris.myapplication.MainActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*">
<!-- Row 1 Starts From Here -->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="3"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:checked="false"
android:onClick="onRadioButtonClicked"
android:text="yes" />
<RadioButton
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:checked="false"
android:onClick="onRadioButtonClicked"
android:text="no" />
</RadioGroup>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="1:"
android:textColor="#000000" />
<EditText
android:id="#+id/e1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="2:"
android:textColor="#000000" />
<EditText
android:id="#+id/e2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="3:"
android:textColor="#000000" />
<EditText
android:id="#+id/e3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="4:"
android:textColor="#000000" />
<EditText
android:id="#+id/e4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="30dp" />
<Button
android:id="#+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_span="3"
android:gravity="center"
android:onClick="onClickreset"
android:text="Reset"
android:textAllCaps="false"
android:textColor="#000000"
android:textStyle="normal" />
</TableLayout>
</LinearLayout>
It's better to use RadioGroup.OnCheckedChangeListener, first of all, get rid of android:onClick attributes and assign an id to RadioGroup in XML:
<RadioGroup
android:id="#+id/yes_no_radio_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="3"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:checked="false"
android:text="yes" />
<RadioButton
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:checked="false"
android:text="no" />
</RadioGroup>
Then make your Activity implements RadioGroup.OnCheckedChangeListener and move there code from onRadioButtonClicked(View v) method:
public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {
//Some activity code
#Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (radioGroup.getCheckedRadioButtonId()) {
case R.id.yes: //Not needed to
e1.setEnabled(false); //which RadioButton clicked
e2.setEnabled(false);
e3.setEnabled(true);
e3.requestFocus();
break;
case R.id.no:
e1.setEnabled(true);
e2.setEnabled(true);
e2.requestFocus();
e2.clearFocus();
e3.setEnabled(false);
break;
}
}
}
Then, assign OnCheckedChangeListener with RadioGroup:
yesNoGroup = findViewById(R.id.radio_group);
yesNoGroup.setOnCheckedChangeListener(this);
And change:
yes.setChecked(false);
no.setChecked(false);
To
yesNoGroup.clearCheck();
This is a Noob question. I am sorry if it has been answered. I have been searching but either could not find or understand the answer. Anyway, I am trying to write a simple weight and balance program for a fleet of aircraft but I'm not sure how to proceed.
I'm trying to figure out how to have the program write to a specific field while a certain radio button is checked.
Could anyone be of any assistance? Thank you!
XML
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_weight_and_balance"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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.tropicaircharters.android.employee.weightAndBalance">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Aircraft Currently Selected:"
android:layout_weight="1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/aircraft_selected"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="50dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="A" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="B" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="C" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="D" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="E" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="F" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/display_a"
android:text="#string/a_weight" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/display_b"
android:text="#string/b_weight" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/display_c"
android:text="#string/c_weight" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/display_d"
android:text="#string/d_weight" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/display_e"
android:text="#string/e_weight" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/display_f"
android:text="#string/f_weight" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Weight" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/weight_display"
android:text="#string/weight_display" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CG" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/cg_display" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="25dp"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Last Weights Entered" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/last_weight"
android:id="#+id/display_last_entry_1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/last_weight2"
android:id="#+id/display_last_entry_2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/last_weight3"
android:id="#+id/display_last_entry_3"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/last_weight4"
android:id="#+id/display_last_entry_4" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/last_weight5"
android:id="#+id/display_last_entry_5"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fuel Tanks"
android:gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:text="Main Tanks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView5"
android:layout_weight="1"/>
<TextView
android:text="Auxiliary Tanks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton2"
android:layout_weight="1" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:text="0 gallons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView3"
android:layout_weight="1"/>
<TextView
android:text="0 gallons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView2"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:text="0 pounds"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView3"
android:layout_weight="1"/>
<TextView
android:text="0 pounds"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView2"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="30dp"
android:text="Weight in Section" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/radio_section">
<RadioButton
android:id="#+id/radio_section_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onRadioButtonClicked"
android:text="A" />
<RadioButton
android:id="#+id/radio_section_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onRadioButtonClicked"
android:text="B" />
<RadioButton
android:id="#+id/radio_section_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onRadioButtonClicked"
android:text="C" />
<RadioButton
android:id="#+id/radio_section_d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onRadioButtonClicked"
android:text="D" />
<RadioButton
android:id="#+id/radio_section_e"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onRadioButtonClicked"
android:text="E" />
<RadioButton
android:id="#+id/radio_section_f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onRadioButtonClicked"
android:text="F" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/enter_weight_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:gravity="center"
android:inputType="number"
android:text="#string/enter_weight" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/add_weight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Add Weight"
android:onClick="add_weight"/>
<Button
android:text="Subtract Weight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/subtract_weight"
android:layout_weight="1"
android:onClick="subtract_weight" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/change_aircraft"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Change Aircraft"
android:onClick="change_aircraft"/>
<Button
android:text="Calculator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/calculator"
android:layout_weight="1"
android:onClick="startActivity(calculator)" />
</LinearLayout>
Java
package com.tropicaircharters.android.employee;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
import android.widget.RadioButton;
import android.widget.TextView;
import android.view.View;
import static android.R.attr.onClick;
import static android.R.id.input;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.V;
import static com.tropicaircharters.android.employee.R.id.display_last_entry_1;
import static com.tropicaircharters.android.employee.R.id.subtract_weight;
import static com.tropicaircharters.android.employee.R.string.a_weight;
import static com.tropicaircharters.android.employee.R.string.weight_display;
public class weightAndBalance extends AppCompatActivity {
//These are weights for each section.
int main_tank_gallons = 0;
int main_tank_weight = main_tank_gallons*6;
int aux_tank_gallons = 0;
int aux_tank_weight = aux_tank_gallons*6;
EditText enter_weight_box;
TextView display_a, weight_display, display_last_weight, display_last_weight_2, display_last_weight_3, display_last_weight_4, display_last_weight_5;
Button add_weight, subtract_weight;
RadioButton radio_section_a, radio_section_b, radio_section_c, radio_section_d, radio_section_e, radio_section_f;
double enter_weight, total_weight, a_weight;
String current_section, last_shizzle, last_shizzle2, last_shizzle3, last_shizzle4, last_shizzle5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weight_and_balance);
enter_weight_box = (EditText) findViewById(R.id.enter_weight_box);
display_a = (TextView) findViewById(R.id.display_a);
weight_display = (TextView) findViewById(R.id.weight_display);
add_weight = (Button) findViewById(R.id.add_weight);
subtract_weight = (Button) findViewById(R.id.subtract_weight);
display_last_weight = (TextView) findViewById(R.id.display_last_entry_1);
display_last_weight_2 = (TextView) findViewById(R.id.display_last_entry_2);
display_last_weight_3 = (TextView) findViewById(R.id.display_last_entry_3);
display_last_weight_4 = (TextView) findViewById(R.id.display_last_entry_4);
display_last_weight_5 = (TextView) findViewById(R.id.display_last_entry_5);
//This displays adds the entered number to A, the Total,
// and creates the last weights entered log.
add_weight.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
enter_weight = Double.parseDouble(enter_weight_box.getText().toString());
a_weight = a_weight + enter_weight;
total_weight = total_weight + enter_weight;
last_shizzle5 = last_shizzle4;
last_shizzle4 = last_shizzle3;
last_shizzle3 = last_shizzle2;
last_shizzle2 = last_shizzle;
last_shizzle = "Added " + Double.toString(enter_weight) + " in A";
//These create displays for totals and the last entered log.
display_a.setText(Double.toString(a_weight));
weight_display.setText(Double.toString(total_weight));
display_last_weight.setText(last_shizzle);
display_last_weight_2.setText(last_shizzle2);
display_last_weight_3.setText(last_shizzle3);
display_last_weight_4.setText(last_shizzle4);
display_last_weight_5.setText(last_shizzle5);
enter_weight_box.setText("");
}
});
//This displays and subtracts the entered number to A, the Total,
// and creates the last weights entered log.
subtract_weight.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
enter_weight = Double.parseDouble(enter_weight_box.getText().toString());
a_weight = a_weight - enter_weight;
total_weight = total_weight - enter_weight;
last_shizzle5 = last_shizzle4;
last_shizzle4 = last_shizzle3;
last_shizzle3 = last_shizzle2;
last_shizzle2 = last_shizzle;
last_shizzle = "Subtracted " + Double.toString(enter_weight) + " in A";
//These create displays for totals and the last entered log.
display_a.setText(Double.toString(a_weight));
weight_display.setText(Double.toString(total_weight));
display_last_weight.setText("Subtracted "+Double.toString(enter_weight)+" in "+"A");
display_last_weight.setText(last_shizzle);
display_last_weight_2.setText(last_shizzle2);
display_last_weight_3.setText(last_shizzle3);
display_last_weight_4.setText(last_shizzle4);
display_last_weight_5.setText(last_shizzle5);
enter_weight_box.setText("");
}
});
}
}
I have used cutsom dialog box in my MainActivity for popup screen.I have added cross button to close
the popup screen. here in my code, that cross button is showing inside
the popup screen.
Now what i want is it has to show at the border of the popup screen.
please help me to get this..
Below is my code..any help would be appreciated...thanks in advance..
Java File
HomePage.java
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.support.v4.app.DialogFragment;
public class HomePage extends Activity {
final Context context = this;
Button b1;
Button b2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
b1 = (Button) findViewById(R.id.button6);
b2 = (Button) findViewById(R.id.button7);
b2.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(HomePage.this,RegisterPage.class);
startActivity(intent);
}
});
b1.setOnClickListener(new OnClickListener() {
#SuppressLint("NewApi")
#Override
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.activity_login_page);
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay(); // getting the screen size of device
Point size = new Point();
display.getSize(size);
int width = size.x - 20; // Set your heights
int height = size.y - 80; // set your widths
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = width;
lp.height = height;
dialog.getWindow().setAttributes(lp);
dialog.show();
ImageView image = (ImageView) dialog.findViewById(R.id.cancel_btn);
image.setImageResource(R.drawable.cancel2);
image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
Button dialogButton = (Button) dialog.findViewById(R.id.button1);
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//dialog.dismiss();
Intent intent = new Intent(HomePage.this,CategoryPage.class);
startActivity(intent);
}
});
dialog.show();
}
});
}
}
XML File
activity_home_page.xml
<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:background="#fff"
tools:context=".MainActivity" >
<LinearLayout android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="5dip"
android:paddingBottom="5dip">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="0dp"
android:src="#drawable/miiskylogo" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/header" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="163dp"
android:orientation="vertical"
android:paddingBottom="0dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin" >
<Button
android:id="#+id/button6"
android:layout_width="230dp"
android:layout_height="50dp"
android:background="#00b0ff"
android:layout_weight="0.1666"
android:textSize="18dp"
android:textColor="#fff"
android:paddingLeft="3dp"
android:layout_gravity="center"
android:layout_marginTop="32dp"
android:drawableLeft="#drawable/lock"
android:text="Login with SVAPP" />
<Button
android:id="#+id/button7"
android:layout_width="230dp"
android:layout_height="50dp"
android:background="#00b0ff"
android:layout_weight="0.1666"
android:textSize="18dp"
android:textColor="#fff"
android:paddingLeft="3dp"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:drawableLeft="#drawable/regis"
android:text="Register with SVAPP" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
activity_login_page.xml
<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:background="#fff"
tools:context="com.example.miiskyproject.Login" >
<ImageView
android:id="#+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/cancel2" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="130dp"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:src="#drawable/miiskylogo" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText1"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="190dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:background="#drawable/loginedit"
android:ems="6"
android:hint="User Name"
android:padding="8dp"
android:textColor="#000"
android:textStyle="bold"
android:textColorHint="#bdbdbd"
android:textSize="13dp" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="190dp"
android:layout_marginRight="15dp"
android:background="#drawable/loginedit"
android:ems="6"
android:hint="Password"
android:inputType="textPassword"
android:padding="8dp"
android:textColor="#000"
android:textStyle="bold"
android:textColorHint="#bdbdbd"
android:textSize="13dp" />
<Button
android:id="#+id/button1"
android:layout_width="70dp"
android:layout_height="35dp"
android:layout_marginRight="20dp"
android:layout_marginTop="190dp"
android:background="#drawable/loginbutton"
android:ems="7"
android:text="Login"
android:textColor="#fff"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelInsurance7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="225dp"
android:text="Forget Your Password?"
android:textSize="13dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/textView2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="280dp"
android:padding="10dp"
android:layout_marginRight="20dp"
android:text="Lorem Ipsum dolor sit amet,"
android:background="#drawable/loginedit"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
I want cross button something like the image below.
Click Here
Try this solution:
<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:background="#fff"
tools:context="com.example.miiskyproject.Login" >
<LinearLayout
android:id="#+id/cancel_layuot"
android:layout_width="match_parent"
android:gravity="right"
android:background="#android:color/transparent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="130dp"
android:layout_height="90dp"
android:layout_below="#+id/cancel_layuot"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:src="#drawable/left_arrow" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#+id/cancel_layuot" >
<EditText
android:id="#+id/editText1"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:layout_marginTop="190dp"
android:background="#drawable/ic_launcher"
android:ems="6"
android:hint="User Name"
android:padding="8dp"
android:textColor="#000"
android:textColorHint="#bdbdbd"
android:textSize="13dp"
android:textStyle="bold" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginRight="15dp"
android:layout_marginTop="190dp"
android:background="#drawable/ic_launcher"
android:ems="6"
android:hint="Password"
android:inputType="textPassword"
android:padding="8dp"
android:textColor="#000"
android:textColorHint="#bdbdbd"
android:textSize="13dp"
android:textStyle="bold" />
<Button
android:id="#+id/button1"
android:layout_width="70dp"
android:layout_height="35dp"
android:layout_marginRight="20dp"
android:layout_marginTop="190dp"
android:background="#drawable/ic_launcher"
android:ems="7"
android:text="Login"
android:textColor="#fff"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelInsurance7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="225dp"
android:text="Forget Your Password?"
android:textSize="13dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#+id/cancel_layuot"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginTop="280dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:text="Lorem Ipsum dolor sit amet,"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
You will see something like this:
Just replace image ic_launcher with the appropriated image.
Here is my Java file for my app that I am working on. The in logcat it is saying there is an error in the initvar() method in this line "length1et = (EditText) findViewById(R.id.etlength1);" I know this is because there is not a variable in the edittext box and I have had this problem before and just put 0's there to start out. Is there a simple command to have nothing there and it will just understand to automatically put in a 0 for the value or is the only way to write some code to treat it as a zero? Below the java code is the xml if that is necessary. In a previous app I have just had it read the edittext box and if nothing is there, set the value to 0 before it does anything else. For the record I know I don't have a button to call the calculate() method I just haven't put that in yet.
package com.example.constructioncalculator;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
public class Paint extends Activity {
int numwin, numdoor;
double areadoor, areawin, lengthft, lengthin, widthft, widthin, heightft,
heightin, areawall, areaceil, paintcon, paintneeded;
EditText length1et, length2et, width1et, width2et, height1et, height2et,
paintconet, paintneededet;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.paintdisp);
initvar();
calculate();
output();
}
private void initvar() {
// TODO Auto-generated method stub
numwin = 0;
numdoor = 0;
areawin = 20;
areadoor = 19.5;
lengthft = 0;
lengthin = 0;
widthft = 0;
widthin = 0;
heightft = 0;
heightin = 0;
areawall = 0;
areaceil = 0;
paintcon = 0;
paintneeded = 0;
length1et = (EditText) findViewById(R.id.etlength1);
length2et = (EditText) findViewById(R.id.etlength2);
width1et = (EditText) findViewById(R.id.etwidth1);
width2et = (EditText) findViewById(R.id.etwidth2);
height1et = (EditText) findViewById(R.id.etheight1);
height2et = (EditText) findViewById(R.id.etheight2);
paintconet = (EditText) findViewById(R.id.etpaintcon);
paintneededet = (EditText) findViewById(R.id.etpaintneeded);
}
private void calculate() {
// TODO Auto-generated method stub
lengthft = Double.parseDouble(length1et.getText().toString());
lengthin = Double.parseDouble(length2et.getText().toString());
widthft = Double.parseDouble(width1et.getText().toString());
widthin = Double.parseDouble(width2et.getText().toString());
heightft = Double.parseDouble(height1et.getText().toString());
heightin = Double.parseDouble(height2et.getText().toString());
paintcon = Double.parseDouble(paintconet.getText().toString());
areaceil = (lengthft + lengthin / 12) * (widthft + widthin / 12);
areawall = areaceil * (heightft + heightin / 12) - (numwin * areawin)
- (numdoor * areadoor);
paintneeded = (areawall / paintcon) * 1.1;
}
private void output() {
// TODO Auto-generated method stub
paintneededet.setText(String.valueOf(paintneeded));
}
}
*********Here is my xml file...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Paint Coverage Estimator"
android:textSize="30dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="#string/paintinst" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tvlength"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Length"
android:textSize="20dp" />
<TextView
android:id="#+id/tvwidth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Width"
android:textSize="20dp" />
<TextView
android:id="#+id/tvheight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Height"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/etlength1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="feet"
android:text="1"
android:textSize="10dp" />
<EditText
android:id="#+id/etlength2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="inches"
android:text="1"
android:textSize="10dp" />
<EditText
android:id="#+id/etwidth1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="feet"
android:text="1"
android:textSize="10dp" />
<EditText
android:id="#+id/etwidth2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="inches"
android:text="1"
android:textSize="10dp" />
<EditText
android:id="#+id/etheight1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="feet"
android:text="1"
android:textSize="10dp" />
<EditText
android:id="#+id/etheight2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="inches"
android:text="1"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="approx paint coverage (ft^2)?" />
<EditText
android:id="#+id/etpaintcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="300" >
<requestFocus />
</EditText>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Paint needed of your buckets" />
<EditText
android:id="#+id/etpaintneeded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Try this:
lengthft = Double.parseDouble(length1et.getText().toString()+0);
But be aware, if the user type in a invalid number and click on the button you haven't implemented yet, your app will crash. So you should probably add a check to all the EditText's before you call calculate().
Or even better, add a function to do it for you:
lengthft = getDouble(length1et);
public double getDouble(EditText et) {
if (!et.getText().equals(null)) {
return Double.parseDouble(et.getText().toString()); //convert your string into integer
} else {
return 0; // or what you want to return if string is Null
}
}
So like so many others i am new to android. I have looked everywhere for an explanation of how to do this but have found none.
this is the app im trying to make.
http://i.stack.imgur.com/JGhJP.png
Im assuming i have to take the input from the top two edittexts and put them into stings and them multiply them and set that answers equal to the bottom edittext?
Im just confused as to how i would correctly do that.
Here is what ive tried so far.
package com.wattzen.testcalculation;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.support.v4.app.NavUtils;
public class Main extends Activity {
private static final String total_Made = "total_Made";
private double tmmade;
private int hedittext;
private int etmade;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
tmmade = 0.0;
} else {
tmmade = savedInstanceState.getDouble(total_Made);
}
}
{
{
hedittext = (EditText) findViewById(R.id.ethours);
etmade = (EditText) findViewById(R.id.etmade);
etmade.addTextChangedListener(etmadeWatcher);}
}
private void updateStandard() {
double tmmade = hedittext * etmade;
tmmade.addTextChangedListener(tmmadeWatcher);
double toTal= tmmade;
}
}
and here is the xml
<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" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hours Worked" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/ethours"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:text="Amount made per hour" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/etmade"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/bcalculate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Calculate" />
</TableRow>
<TableRow
android:id="#+id/tableRow7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total Money Made" />
</TableRow>
<EditText
android:id="#+id/tmmade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:ems="10"
android:focusable="false"
android:focusableInTouchMode="false"
android:inputType="number" />
</TableLayout>
I greatly appreciate any help you guys can give me. thanks.
You should be getting a ton of syntax errors that should clue you in on lines that need changing.
Since hedittext and etmade are ints, you cannot set them equal to an EditText, as you do in onCreate().
First you need to get the actual content of the EditTexts. You can do this by calling the edit text's getText() methods.
Then you need to parse the result of getText as an integer. You can do this using the Integer wrapper class' parseInt() method.
It should look more like this:
EditText editTextA = (EditText) findViewById(R.id.ethours);
int hours = Integer.parseInt(editTextA.getText().toString())
Your first step is to assign an onClick listener the calculate button. Once you do this, reference both the editTexts within onCreate. After this, you can get the text from the edit texts using the getText() function.
Here is a basic mockup of the code. Id suggest checking if the input is valid first and then multiplying
Button bcalculate = (Button)findViewById(R.id.bcalculate);
EditText hedittext = (EditText)findViewById(R.id.ethours);
EditText etmade = (EditText)findViewById(R.id.etmade);
EditText tmmade = (EditText)findViewById(R.id.edittext3);
bcalculate.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View view)
{
try{
double e1 = Double.parseDouble(hedittext.getText().toString());
double e2 = Double.parseDouble(etmade.getText().toString());
tmmade.setText(e1*e2);
} catch (NumberFormatException e) {
}
});