ive 문자열 변환에 문제가 발생했습니다. 숫자 (BigDecimal)가 업데이트 될 때 화면에 출력되는 시스템을 구현하려고합니다. 따라서 BigDecimal (dpzahl)의 하위 클래스를 만들어 업데이트 된 번호를 검색하고 uid에 updaterequest를 보냅니다.문자열 변환 issure
그래서 기본적으로 : 나는 String.xml에서 문자열 (텍스트)을 저장합니다. 예 :
"value of %s: %s"
그리고 인수의 참조를 인수에 저장합니다. 이러한 참조는 Strings, SpannableStrings 또는 dpzahl이 될 수 있습니다.
그러나 및 String.format 필자을 준비하는 것은 문제가 있어요 동안 :
Log.d(MainActivity.LOGTAG,"update request is executed");
final Object[] ARGS = new CharSequence[argumente.size()]; //to be put into the formater
int i = 0;
for(Object ooo: arguments) { // private ArrayList<Object> arguments; is a class variable
if (ooo instanceof dpzahl) { // dpzahl extends BigDecimal to get the number i want to format
ARGS[i] = haupt.format_bigies(((dpzahl) ooo).get()); //get the formated string
Log.d(MainActivity.LOGTAG,"number print:"+ARGS[i].toString());
}if(ooo instanceof SpannableString){ //some other arguments i may need in the string.format argument list
ARGS[i] = ((SpannableString)ooo);
}else{ //for any other object, mostly Strings
ARGS[i] = ooo.toString();
}
if (ooo instanceof dpzahl) { //only for debugprint
Log.d(MainActivity.LOGTAG,"loopvalue dpzahl:"+ARGS[i].toString());
}
Log.d(MainActivity.LOGTAG,"loopvalue:"+ARGS[i].toString());
i++;
}
for(Object ooo: ARGS) { //only for debugprint
if(ooo instanceof String){
Log.d(MainActivity.LOGTAG, "againarg Stirng:" + ((String)ooo));
}else if(ooo instanceof SpannableString) {
Log.d(MainActivity.LOGTAG, "againarg SpannableString:" + ((SpannableString)ooo).toString());
}
Log.d(MainActivity.LOGTAG, "againarg Object:" + ooo.toString());
}
sicht.post(new Runnable() {
@Override
public void run() {
Log.d(MainActivity.LOGTAG,"allargs:"+ Arrays.toString(ARGS));
view.setText(SpanFormatter.format(text, ARGS));//Copyright © 2014 George T. Steel, replace string.format for SpannableString
view.invalidate();//the linked TextView
}
});
내가 SpannableString "testvalue"에 넣으면 출력이
출력 4의 BigDecimal의 표현 :
을update request is executed
loopvalue:testvalue
formated BigDecimal:4
number print:4
loopvalue dpzahl:4.000000000
loopvalue:4.000000000
againarg SpannableString:testvalue
againarg Object:testvalue
againarg Stirng:4.000000000
againarg Object:4.000000000
allargs:[testvalue , 4.000000000]
그래서 TextView 문자열은 "testvalue : 4 값"이어야하지만 "testvalue 값 : 4.000000000"이어야합니다.
그렇다면 ARGS [1]의 값은 먼저 String "4"의 값을 가져오고 나중에 "4.000000000"의 값은 포매터로 전달되기 전에 왜 필요합니까?
추신 : 문제는 내가이 전에 포맷터에 선
final Object[] ARGS = new CharSequence[argumente.size()];
을 SpannableString을 구현할 때 나타나는
final Object[] ARGS = new String[argumente.size()];
모두 잘 작동했다. 하지만 SpannableString은 CharSequence 인 다음 상위 공통 분모가 필요하므로 String을 확장하지 않습니다.
쪽 : 도움이되지 않습니다
final Object[] ARGS = new Object[argumente.size()];
를 사용하여.
에 완전히 옳다. 두 문장이 어디서 발생했는지는 알지 못합니다. 먼저 올바른 명령문은 executet이지만 다음 if는 dpzahl 개체를 SpannableString과 비교할 것이고 false이기 때문에 인수는 기본 .tostring() 메서드로 설정됩니다. – Piea
@Piea 왜 내가 downvoted있어 모르겠어요. –
내 평판이 나올 때까지 투표를 할 수 없기 때문에 내 투표가 아니었다. – Piea