我有一个简单的editText控件。当我按下删除时,它会向后移动但不会删除hint_status中的渲染文本。
这是什么原因?
<EditText
android:id="@+id/editStatus"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/buttonTweet"
android:ems="10"
android:inputType="textMultiLine"
android:text="@string/hint_status" >
<requestFocus />
</EditText>
视图如下所示
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_status, container, false);
editStatus = (EditText) view.findViewById(R.id.editStatus);
buttonTweet = (Button) view.findViewById(R.id.buttonTweet);
textCount = (TextView) view.findViewById(R.id.textCount);
buttonTweet.setOnClickListener(this);
editStatus.setOnClickListener(this);
defaultTextColor = textCount.getTextColors().getDefaultColor();
editStatus.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
int count = 140 - editStatus.length();
textCount.setText(Integer.toString(count));
textCount.setTextColor(Color.GREEN);
if (count < 10)
textCount.setTextColor(Color.RED);
else
textCount.setTextColor(defaultTextColor);
}
});
return view;
}
@Override
public void onClick(View v) {
String status = editStatus.getText().toString();
Log.d(TAG, "onClicked with status: " + status);
if (v == editStatus) {
editStatus.setHint("");
editStatus.setText("");
}
new PostTask().execute(status);
}
答案 0 :(得分:1)
为了显示提示,您必须使用android:hint
XML注释。
你的XML看起来像这样:
<EditText
android:id="@+id/editStatus"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/buttonTweet"
android:ems="10"
android:inputType="textMultiLine"
android:hint="@string/hint_status" >
<requestFocus />
</EditText>