就是要打字,怎麼樣之 AlertDialog & EditText
AlertDialog能夠勾選,這麼簡單的的程式,隨便寫寫就OK了,再來要寫些甚麼呢?就再弄個其他的樣式來看看吧,讓跳出來的畫面可以打字吧!!!
1. 建立專案
2. 加個Button
3. Source Code
package com.example.ex004;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView tv;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) MainActivity.this.findViewById(R.id.textView1);
btn = (Button) MainActivity.this.findViewById(R.id.button1);
final LinearLayout ll = new LinearLayout(this);
final EditText et = new EditText(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(et);
btn.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new AlertDialog.Builder(MainActivity.this)
.setTitle("EX004")
.setView(ll)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
tv.setText(et.getText());
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
}
}).show();
}
});
}
@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;
}
}
|
4. 按個按鈕吧
5. 就是這個框
6. 感動吧!再按一次
7. 蝦密,掛了
8. 去找漏格貓吧
9. 這是什麼鳥訊息
10-07 14:08:15.105: E/AndroidRuntime(636): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
|
累了,有機會再來除蟲吧!!!
範例 : EX004
標籤: AlertDialog, EditText
0 個意見:
張貼留言
<< 首頁