Textview Android não suportando quebra de linha
Estou criando uma exibição personalizada programaticamente que está exibindo o texto que é analisado de um arquivo XML. O texto é longo e contém o caractere "/ n" para quebras de linha de força. Por algum motivo, a exibição de texto está exibindo o / n e não há quebras de linha. Aqui está o meu código:
// 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);
O texto do arquivo XML é assim:
Now is the time /n for all good men to /n come to the aid of their /n party
Ele deve ser exibido como tal;
Now is the time
for all good men to
come to the aid of their
party
Há cenário que estou perdendo?
ATUALIZAR
\ r \ n funciona se eu codificar isso na minha opinião. ie:
String fireText = "Now is the time \r\n for all good men \r\n to come to the aid";
Na verdade, \ n também funciona se eu codificá-lo:
String fireText = "Line one\nLine two\nLine three";
Para sua informação
System.getProperty("line.separator");
isso retorna uma string de "/ n", portanto não há necessidade de converter para "/ r / n".
Infelizmente, meus dados são originados em um arquivo XML que é analisado e armazenado em um hashmap. Eu tentei o seguinte:
String fireText = body1.toString().replaceAll("\n", "\r\n");
O \ n não está sendo substituído por \ r \ n. Poderia ser porque eu estou convertendo de um objeto para String?