我有点困惑,我将我的应用程序设置为一个简单的转换器,但它无法正常工作。我的日志说它与myclickhandler有关,但我不知道该去哪里。
package hmdywifinal.com;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
public class Butterfliesstart extends Activity {
private ImageButton ConvertButterflies = null;
private ImageButton Butterfliesstart1 = null;
private EditText YourWeight = null;
private TextView Output = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.butterfliesstart);
//GO BACK
ImageButton Butterfliesstart1 = (ImageButton)findViewById(R.id.testbutton2);
Butterfliesstart1.setOnClickListener(new View.OnClickListener() {
public void onClick(View argo) {
setResult(RESULT_OK);
finish();
};
});
//Set IDS
ImageButton ConvertButterflies = (ImageButton)findViewById(R.id.testbutton1);
//Set Values
class ToButterflies implements View.OnClickListener
{
public void onClick(View v)
{
convertToButterflies();
}
private void convertToButterflies()
{
String ButterflyString = YourWeight.getText().toString();
double f = Double.parseDouble(ButterflyString);
double c = 5.0/9.0 * (f - 32.0);
EditText YourWeight = (EditText)findViewById(R.id.editText1);
Output.setText(String.valueOf(c));
}
}
Output = new EditText(this);
EditText Output = (EditText)findViewById(R.id.editText2);
//Initialize
Butterfliesstart1 = new ImageButton(this);
ConvertButterflies = new ImageButton(this);
YourWeight = new EditText (this);
XML:
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Butterfliesstart"></TextView>
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
<ImageButton
android:text="and back."
android:src="@drawable/dirtbutton"
android:id="@+id/testbutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick=""
>
</ImageButton>
<ImageButton
android:src="@drawable/bumblebees"
android:id="@+id/testbutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="myClickHandler"
>
</ImageButton>
</LinearLayout>
按下按钮进行转换后,强行关闭。我错过了代码中的任何内容吗?
答案 0 :(得分:0)
除非您尚未发布所有内容,否则身份为ImageButton
的{{1}}的{{1}}定义为testbutton1
,但您尚未定义该方法。每次按下它都会非常成功。
我同意JoxTraex的观点,但是如果你花时间学习使用你拥有的工具,这很容易跟踪。阅读DDMS。