簡體   English   中英

如果我改用 editText,如何更改我的 textView 更可編輯?

[英]How can I change my textView more editable should I editText instead?

正如您在我的計算器應用程序中看到的那樣,它只能在最后添加或刪除文本或數字,因為我使用的是 textView。是否有替代方案,我可以從使用我提供的按鈕而不是默認按鈕的任何 position 進行編輯。 在此處輸入圖像描述

是的,您可以使用編輯文本,也可以在對話框中使用編輯文本。 單擊 texrview 后,將顯示一個帶有 edittext 的對話框,以便用戶可以從那里進行編輯,而不是從 edittext 字符串設置 textview。 這將是程序化的,沒有 xml 編輯。

dia.setMessage("yourmessage");
final EditText edittext1 = new 
EditText(MainActivity.this); 
LinearLayout.LayoutParams
Ipar = new 
LinearLayout.LayoutParams
(LinearLayout.LayoutParams.WRAP_CONTENT, 
LinearLayout.LayoutParams.WRAP_CONTENT); 
edittext1.setLayoutParams(Ipar);
dia.setView(edittext1);
if (!textview1.equals("")) {
edittext1.setText((textview1.getText()));
} dia.setPositiveButton("O", new 
DialogInterface.OnClickListener() 
{
@Override
public void onClick(DialogInterface _dialog, int _which) {
    textview1.setText((edittext1.getText()));
    
}
});
dia.setNegativeButton("X", new DialogInterface.OnClickListener() 
{
@Override
public void onClick(DialogInterface _dialog, int _which) {
    
}
});
dia.create().show();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM