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);
}
}
答案 0 :(得分:1)
正如@Varun所说,没有findById()
方法。您可能正在考虑findViewById()
。
您可以通过检查任何示例Android活动并查看它如何访问小部件来自行找到此信息。 SDK安装中有许多示例活动,还有在线。