1 回答

TA貢獻1816條經驗 獲得超4個贊
如果你只是想
如果存在這樣的標簽,則刪除
"<#c>"
行首的標簽,并且如果該行中有這樣的標簽,則將列表項中的文本居中
那么您可以嘗試在設置列表項文本內容的代碼部分中這樣做:
// get the TextView instance first
TextView textView = ((TextView) rootView.findViewById(R.id.text2));
// then get the text in order to check if it begins with the tag
String text = args.getString(ARG_OBJECT2);
// find out if it begings with the tag
boolean beginsWithTag = text.startsWith("<#c>");
// then handle the case of a leading tag
if (beginsWithTag) {
// replace the tag with an empty String and trim it
text = text.replace("<#c>", "").trim(); // removes the leading tag
text.trim(); // removes all trailing or leading whitespaces
textView.setGravity(Gravity.CENTER);
}
// finally just add the text
textView.setText();
請注意,我沒有您的完整代碼,無法以任何合適的方式對其進行測試。您必須自己調試任何錯誤。您也可以縮短此代碼,但我認為多寫幾行可以顯示在這種情況下更清楚地執行此操作的方法。
添加回答
舉報