2012-05-31 139 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'中放入一行。 –