在设置来自 JSON 的文本的 TextView 中使用“&minus”而不是“-”

"&minus" instead of "-" in TextView which setting text from JSON

我有天气应用程序,可以从这里获取天气信息 json:

http://icomms.ru/inf/meteo.php/?tid=44

"temp" 值有一个负值(例如:"temp":"−16"),当我使用 retrofit2 从 json 获取值并在文本视图中显示时,它显示 −16 而不是 -16

如何显示 -16 而不是 −16

来自 RecyclerViewAdapter 的片段(我用它来显示多天的天气信息),我将文本设置为 textview

@Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Meteo meteo = data.get(position);
        holder.date.setText(meteo.date);
        holder.tod.setText(meteo.tod);
        holder.pressure.setText(meteo.pressure);

        // THIS IS TEMPERATURE SETTING TEXT LINE
        holder.temp.setText(meteo.temp);

        holder.humidity.setText(meteo.humidity);
        holder.wind.setText(meteo.wind);
        holder.cloud.setText(meteo.cloud);
}

天气数据class:

public class Meteo {
    public String date;
    public String tod;
    public String pressure;
    public String temp;
    public String humidity;
    public String wind;
    public String cloud;
}

响应正文:

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(APIService.HOST)
            .addConverterFactory(GsonConverterFactory
                    .create())
            .build();

    APIService apiService = retrofit.create(APIService.class);

    Call<List<Meteo>> call = apiService.getMeteo(44);

    call.enqueue(new Callback<List<Meteo>>() {
        @Override
        public void onResponse(Call<List<Meteo>> call, Response<List<Meteo>> response) {
            MeteoAdapter adapter = new MeteoAdapter(response.body());
            // Method show just shows list of weather data
            getViewState().show(adapter);
        }

        @Override
        public void onFailure(Call<List<Meteo>> call, Throwable t) {
            Log.d("MyLog", "WRONG");
        }
    });

试试这个。我用它来格式化文本视图中的 html 标签:

String s = Html.fromHtml("&minus;16");
tv.setText(s);

推理:它将文本设置为 Spanned 对象,而不是字符串。

注意:目前无法测试,如果不起作用请见谅。