我讀過大量的問題,無法找到有效的答案。反正,我是新至Android/java編程,並不能得到我的按鈕的onClick讓我的EditText的內容,並相應地使用它們(?)我覺得是我的問題,我的繼承人代碼Android EditText或可能的OnClickEvent問題
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Fittings extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button go = (Button)findViewById(R.id.GoButton);
go.setOnClickListener(this);
}
public void onClick(View v) {
EditText circum = (EditText)findViewById(R.id.CtoD);
int C = Integer.parseInt(circum.getText().toString());
TextView CtoDAnswer = (TextView)findViewById(R.id.CtoDAnswer);
CtoDAnswer.setText((int) (C * 0.3183));
}
}
試試go.setOnClickListener(Fittings.this); – Sumant 2011-05-29 02:27:49