0
package com.example.android.home;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.*;
public class HomeActivity extends Activity {
/** Called when the activity is first created. */
private EditText input;
private EditText result;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
input = (EditText) findById(R.id.input1);
result = (EditText) ***findById***(R.id.result); //Error:Undefined for the type HomeActivity
input.addKeyListener(new View.OnKeyListener() { Error: Undefined for the type EditText
public boolean onKey(View v, int keycode, KeyEvent keyevent) {
if (keyevent.getAction() == KeyEvent.ACTION_UP) {
doCalculation();
}
return false;
}
});
}
private void doCalculation()
{
String strValue = input.getText().toString();
int resultt = Integer.parseInt(strValue) * 2;
result.setText("Result: "+ resultt);
}
}
向我們展示您的main.xml佈局。 – 2011-06-11 11:28:57
你能發佈你的主佈局的xml嗎? – Flo 2011-06-11 11:29:30
它甚至如何編譯。它應該是'findViewById()'而不是'findById()' – Varun 2011-06-11 11:59:37