练练手,熟悉一下Android的开发。Android SDK的帮助文档很有帮助,仔细读读,路径为:
android-sdk-windows\docs
第一个例子:
在EditText中输入,在TextView中及时显示。练习了View, Listener, findViewById, getString(resID), Log.
package ian.study.demos;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
public class HelloWrold extends Activity {
static final String STR_DEFAULT_SAY = "It's not my first Android App. LoL";
private TextView tvSay;
private EditText etSay;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tvSay = (TextView)findViewById(R.id.tvSay);
tvSay.setText(STR_DEFAULT_SAY);
etSay = (EditText)findViewById(R.id.etSay);
etSay.setText(R.string.saysomething);
etSay.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
Log.d(getString(R.string.app_name), "after changed");
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
tvSay.setText(etSay.getText());
Log.d(getString(R.string.app_name), "on changed");
}
});
}
}