我一直在嘗試為此尋找解決方案,但沒有幸運地找到正確的答案。
所以我的問題是.. 我想在單擊某個按鈕后洗掉 EditText 中的第一個換行符。
First Line <- This should be removed after I click the button and the rest will remain.
Second Line
Third Line
Fourth Line
EditText txt = findViewById(R.id.editTextID);
Button btn = findViewById(R.id.btnID);
btn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
String firstLine = txt.getText().toString().substring(0, txt.getText().toString().indexOf("\n"));
String removeFirstLine = firstLine.substring(0, firstLine.length()-1);
txt.setText(removeFirstLine);
}
});
但是每次我單擊按鈕時只留下 1 行。
uj5u.com熱心網友回復:
我相信這會做你想做的:-
btn.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View view) {
txt.setText(txt.getText().toString().substring(txt.getText().toString().indexOf("\n") 1));
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/396401.html
上一篇:變數內的值的名稱是什么?
