Skip to content

Instantly share code, notes, and snippets.

@SZooo
Created August 11, 2014 11:14
Show Gist options
  • Save SZooo/9740d0357559e14cfba3 to your computer and use it in GitHub Desktop.
Save SZooo/9740d0357559e14cfba3 to your computer and use it in GitHub Desktop.
EditText
public class kk extends Activity {
private EditText edtName;
private EditText edtPas;
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.kk);
tv = (TextView) findViewById(R.id.message);
edtName = (EditText) findViewById(R.id.edtname);
edtPas = (EditText) findViewById(R.id.edtpas);
edtPas.setHint("请输入密码");
edtPas.setOnKeyListener(new pass());
}
class pass implements OnKeyListener {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
tv.setText("你的用戶名為:" + edtName.getText().toString() + "密碼:" + edtPas.getText().toString());
return false;
}
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="${relativePackage}.${activityClass}">
<TextView
android:id="@+id/tvname"
android:textSize="20dip"
android:text="请输入姓名:"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/edtname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLength="10"
android:hint="输入用户名"
android:textColorHint="#FF7F00"
/>
<TextView
android:id="@+id/tvpas"
android:textSize="20dip"
android:text="请输入密码"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/edtpas"
android:maxLength="10"
android:password="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment