package com.example.edittext;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.view.Menu;
public class MainActivity extends Activity {
TextView tv;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
setContentView(ll);
tv = new TextView(this);
tv.setText("讓我這個魔術師來猜猜你寫了什麼字!!。");
et = new EditText(this);
ll.addView(tv);
ll.addView(et);
et.setOnKeyListener(new SampleKeyListener());
}
class SampleKeyListener implements OnKeyListener
{
public boolean onKey(View v, int keycode, KeyEvent e)
{
EditText tmp = (EditText) v;
tv.setText("是" + tmp.getText() + "對吧。");
return true;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
留言列表