Android Основы: пользовательский ввод - добавить TextViews для цены, символ валюты не отображается - PullRequest
1 голос
/ 20 февраля 2020

Символ валюты не появляется после того, как я следую всем инструкциям. Я попытался добавить Local.UK в getCurrencyInstant (), как предлагали другие комментарии, однако это не сработало, Как видно из предварительного просмотра .

Я попытался очистить и перестроить проект, но ни один из них не работал.

Код для основного действия xml это

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Quantity"
    android:textAllCaps="true"
    android:textSize="16sp"
    android:layout_marginTop="16dp"
    android:layout_marginBottom="16dp"
    android:layout_marginStart="14dp"/>
<TextView
    android:id="@+id/quantity_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="0"
    android:textSize="16sp"
    android:textColor="#000000"
    android:layout_marginBottom="16dp"
    android:layout_marginStart="14dp"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Price"
    android:textAllCaps="true"
    android:textSize="16sp"
    android:layout_marginBottom="16dp"
    android:layout_marginStart="14dp"/>

<TextView
    android:id="@+id/price_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="14dp"
    android:layout_marginBottom="16dp"
    android:text="0"
    android:textColor="#000000"
    android:textSize="16sp" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Order"
    android:textAllCaps="true"
    android:textSize="16sp"
    android:layout_marginBottom="16dp"
    android:layout_marginStart="14dp"
    android:onClick="submitOrder"/>

Код для основного действия java:

package com.example.android.justjava;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.text.NumberFormat;

/**
 * This app displays an order form to order coffee.
 */
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

/**
 * This method is called when the order button is clicked.
 */
public void submitOrder(View view) {
    display(1);
}

/**
 * This method displays the given quantity value on the screen.
 */
private void display(int number) {
    TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
    quantityTextView.setText("" + number);
}
/**
 * This method displays the given price on the screen.
 */
private void displayPrice(int number) {
    TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
    priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
}
}
...