2012-05-31 137 views
0

我有一個活動有EditTextButtonEditText中的數據在開始時不可編輯,但在Button被按下時變爲可編輯。我嘗試在xml佈局中使用android:editable="false",但它不起作用。有人可以幫助我嗎?編輯文本框沒有被編輯

回答

1

您需要先設置文本編輯編輯屬性設置爲false在你的XML佈局:

<EditText 
    ... 
    android:id="@+id/input" 
    android:clickable="false" /> 

,然後單擊該按鈕時,設置文本編輯可編輯:

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    input = (EditText) findViewById(R.id.input); 
    button = (Button) findViewById(R.id.button); 

    button.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View v) 
     { 
      input.setClickable(true); 
     } 

    }); 
} 
+1

嘿,沒有編輯文本字段的setEditable()函數。呵呵我可以這樣做嗎? – user47

+0

糟糕。不幸的是,'editable'屬性只能通過XML以編程方式公開,您應該使用'setEnabled'或'setFocusable'或'setClickable'。但是,使用這些方法時,您將無法選擇並複製文本...代碼已更新。 –

1
editText.setEnabled(true); or editText.setEnabled(false); 

如果傾斜的作品則Editable false

0
<EditText 
    ... 
    android:id="@+id/urId" 
    android:clickable="True" /> 

這對我有用,試試你的運氣。

+0

DjRaf

+0

歡迎來到Stack Overflow!我編輯了你的答案。如果你想在這裏顯示代碼,你應該縮進4個空格。這會自動在'code markdown'中放入一行。 –