约翰删除
简删除
ABC删除
XYZ删除
尝试编写Android代码以删除按下删除按钮的相应名称。但是当按下删除按钮时无法获取相应的名称,我需要使用 only String或stringBuffer方法完成这项任务。
任何人都可以帮助我完成这项任务。
以下是模拟:
答案 0 :(得分:0)
此功能将起作用。
private void deleteIt(Button button,TextView textView)
{
button.setVisibility(View.INVISIBLE); //Or You Can Use View.GONE
textView.setText(""); //Setting A Null Text In The TextView.
}
例如: -
xyzButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
deleteIt(xyzButton,xyzTextView);//xyzTextView = Your Text View To Delete
}
});
答案 1 :(得分:0)
以下是上述帖子的代码。
public static void deleteText(TextView textView,Button button){
String text=textView.getText().toString();
StringBuffer stringBuffer = new StringBuffer(text);
StringBuffer deletedString = stringBuffer.delete(0, stringBuffer.length());
textView.setText(deletedString);
button.setVisibility(button.INVISIBLE);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.ABCDeleteButtonID: deleteText(ABCTextview,ABCDeleteButton);
break;
case R.id.JhondeleteButtonID:deleteText(JhonTextView,JhondeleteButton);
break;
case R.id.JaneDeleteButtonID:deleteText(JaneTextView,JaneDeleteButton);
break;
}
}