Here is my code below. When I just had the EditText Box code, it loaded fine. When I added the ImageButtons and listeners, it will not run at all. I do not want to add method code until I can get it to at least run. I am running on API 7
package org.chrome9.golfCalc;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
public class launchCalculator extends Activity {
private EditText txtEditScore;
private EditText txtEditRating;
private EditText txtEditSlope;
private ImageButton btnCalc;
private ImageButton btnNext;
private ImageButton btnBack;
private ImageButton btnReset;
private ImageButton btnCourseHandicap;
private TextView txtHeader;
private TextView txtEnterScore;
private TextView txtEnterRating;
private TextView txtEnterSlope;
private TextView txtBottom;
// Variables in the application
int[] Score = new int[20];
double[] Rating = new double[20];
double[] Slope = new double[20];
double CourseHandicapResult = 0;
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnCalc = (ImageButton)findViewById(R.id.btnCalc);
btnCalc.setEnabled(false);
btnCalc.setOnClickListener(calcListener);
btnNext=(ImageButton)findViewById(R.id.btnNext);
btnNext.setEnabled(false);
btnNext.setOnClickListener(nextListener);
btnBack=(ImageButton)findViewById(R.id.btnBack);
btnBack.setEnabled(false);
btnBack.setOnClickListener(backListener);
btnReset=(ImageButton)findViewById(R.id.btnReset);
btnReset.setEnabled(false);
btnReset.setOnClickListener(resetListener);
btnCourseHandicap=(ImageButton)findViewById(R.id.btnCourseHandicap);
btnCourseHandicap.setEnabled(false);
btnCourseHandicap.setOnClickListener(courseHandicapListener);
txtHeader = (TextView) findViewById(R.id.txtHeader);
txtHeader = (TextView) findViewById(R.id.txtEnterScore);
txtHeader = (TextView) findViewById(R.id.txtEnterRating);
txtHeader = (TextView) findViewById(R.id.txtEnterSlope);
txtHeader = (TextView) findViewById(R.id.txtBottom);
txtEditScore = (EditText)findViewById(R.id.txtEditScore);
txtEditScore.requestFocus();
txtEditScore.setText("0");
txtEditRating = (EditText) findViewById(R.id.txtEditRating);
txtEditRating.setText("0");
txtEditSlope = (EditText) findViewById(R.id.txtEditSlope);
txtEditSlope.setText("0");
}
private OnClickListener calcListener=new OnClickListener()
{
public void onClick(View v)
{
}
};
private OnClickListener nextListener=new OnClickListener()
{
public void onClick(View v)
{
}
};
private OnClickListener backListener=new OnClickListener()
{
public void onClick(View v)
{
}
};
private OnClickListener resetListener=new OnClickListener()
{
public void onClick(View v)
{
}
};
private OnClickListener courseHandicapListener=new OnClickListener()
{
public void onClick(View v)
{
}
};
}
Main XML
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/tblLayout"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@color/background" xmlns:android="http://schemas.android.com/apk/res/android">
/* Row 1: This is the Row for the header */
<TableRow>
<TextView android:id="@+id/txtHeader" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_column="0"
android:layout_span="4" android:typeface="serif" android:textSize="18px"
android:textColor="@color/darkblue" android:paddingBottom="15px"
android:paddingTop="5px" android:text=" The Chrome9 Calculator v1.0" />
</TableRow>
/* Row 2: This is the Row for Entering the score */
<TableRow>
<TextView android:id="@+id/txtEnterScore"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_column="0" android:layout_span="2" android:textSize="18px"
android:textColor="@color/black" android:text=" Enter Your Score: " />
<EditText android:id="@+id/txtEditScore"
android:layout_height="wrap_content" android:numeric="integer"
android:layout_column="2" android:layout_span="1" />
</TableRow>
/* Row 3: This is the Row for entering the Course rating */
<TableRow>
<TextView android:id="@+id/txtEnterRating"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_column="0" android:layout_marginRight="30px"
android:textSize="18px" android:textColor="@color/black"
android:text=" Enter Course Rating" />
<EditText android:id="@+id/txtEditRating"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:numeric="decimal" android:layout_column="2"
android:layout_span="1" />
</TableRow>
/* Row 4: The row for entering the course slope */
<TableRow>
<TextView android:id="@+id/txtEnterSlope"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_column="0" android:textSize="18px" android:textColor="@color/black"
android:text=" Enter Course Slope" />
<EditText android:id="@+id/txtEditSlope"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:numeric="decimal" android:layout_column="2"
android:layout_span="1" />
</TableRow>
/* This separator view is used to separate
the area below the buttons which will display the
calculation results */
开发者_开发问答<View android:layout_height="2px" android:background="#DDFFDD"
android:layout_marginTop="5dip" android:layout_marginBottom="5dip" />
// Row 5 contains a text at column 2
<TableRow>
<TextView android:id="@+id/txtHandicap" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="18px"
android:textColor="@color/black" android:text="Handicap:"
android:layout_column="2" android:layout_span="1" />
</TableRow>
/* Row 6: Is the calcuation button and the textbox for the
results of the handicap calculation*/
<TableRow>
<ImageButton android:id="@+id/btnCalc" android:src="@drawable/calculator32"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<EditText android:id="@+id/txtHandicap" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:numeric="decimal"
android:layout_column="2" android:layout_span="1" />
</TableRow>
/* Row 7: Back button */
<TableRow>
<ImageButton android:id="@+id/btnBack" android:src="@drawable/back32"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_column="0" android:layout_span="1" />
<Button android:id="@+id/btnCourseHandicap"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_column="2" android:text="Course" android:textSize="18px" />
</TableRow>
/* Row 8: The forward and reset/edit buttons */
<TableRow>
<ImageButton android:id="@+id/btnNext" android:src="@drawable/forward32"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_column="0" />
<ImageButton android:id="@+id/btnReset"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_column="2" android:src="@drawable/edit32" />
</TableRow>
/* Row 9: This is just a row for the plug of the company */
<TableRow android:paddingBottom="10dip" android:paddingTop="5dip">
<TextView android:id="@+id/txtBottom" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_column="0"
android:textSize="14px" android:textColor="@color/darkblue"
android:text=" www.chrome9.org" />
</TableRow>
// End of all rows and widgets
</TableLayout>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.chrome9.golfCalc"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon">
<activity android:name=".launchCalculator"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
精彩评论