我正在以编程方式创建一个自定义视图,显示从XML文件解析的文本.文本很长,包含强制换行符的"/ n"字符.由于某种原因,文本视图显示/ n并且没有任何换行符.这是我的代码:
// get the first section body
Object body1 = tempDict.get("FIRE");
String fireText = body1.toString();
// create the section body
TextView fireBody = new TextView(getActivity());
fireBody.setTextColor(getResources().getColor(R.color.black));
fireBody.setText(fireText);
fireBody.setTextSize(14);
fireBody.setSingleLine(false);
fireBody.setMaxLines(20);
fireBody.setBackgroundColor(getResources().getColor(R.color.white));
// set the margins and add to view
layoutParams.setMargins(10, 0, 10, 0);
childView.addView(fireBody,layoutParams);
Run Code Online (Sandbox Code Playgroud)
XML文件中的文本是这样的:
Now is the time /n for all good men to /n come to the aid of their /n party
Run Code Online (Sandbox Code Playgroud)
它应该如此显示;
Now is the time
for all good men to
come to the aid …Run Code Online (Sandbox Code Playgroud) 我需要使用Formater创建一个String来显示一些双浮点值.我不清楚如何编码它.这是我有的:
Double dWeightInKg = 100;
Double dWeightInLbs = 220:
String headerText = String.format("%.0f kg / %.0f lbs",Double.toString(dWeightInKg) , Double.toString(dWeightInLbs));
Run Code Online (Sandbox Code Playgroud)
我正在寻找以下输出:
100 kg / 220 lbs
Run Code Online (Sandbox Code Playgroud)
我在String.format行上得到了一个runtimeexception - badArgumentType(formater).