[英]How do I hide the text that the user enters into a password JTextField?
[英]how to add the text which the user enters in the edit text box into the listview?
我創建了一個包含listview的布局。 我已經添加了一個按鈕,點擊它后會出現一個帶編輯文本框的警告對話框和兩個選項OK和CANCEL。 我想將用戶在編輯文本框中輸入的項目添加到列表視圖中。 任何人都可以幫我解決這個問題嗎?
這是顯示Alert對話框的代碼,該值必須顯示為listview的項目。
if(v.getId() == addbtn.getId())
{
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Add new location");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Editable value = input.getText();
// Do something with value!
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
}
您應該使用ArrayAdapter並將其綁定到ListView。 當用戶輸入新值時,將其添加到ArrayAdapter並調用mListView.notifyDataSetChanged()。
這里有一個很好的設置ListView和ArrayAdapter的例子http://anujarosha.wordpress.com/2011/11/17/how-to-create-a-listview-using-arrayadapter-in-android/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.