Строка, не показанная из другого используемого пакета. - PullRequest
0 голосов
/ 05 марта 2020

Я хотел получить название пиццы на странице счета, чтобы оно не отображалось (пусто).

Меню. java:

bundle = new Bundle();
        bundle.putString("name",pizzaName);
y = new Intent(this,Bill.class);
        y.putExtras(bundle);
startActivity(y);

Bill. java :

text1=(TextView)findViewById(R.id.textView6);
y= new Intent();
        bundle=getIntent().getExtras();
        Name=bundle.getString("name");
text1.setText();

Вывод:

Ответы [ 4 ]

0 голосов
/ 05 марта 2020

Нет необходимости получать y = новое намерение (); когда вы получаете данные из пакета

text1 = (TextView) findViewById (R.id.textView6);

bundle = getIntent (). getExtras ();

Name = bundle.getString ("name");

text1.setText ();

0 голосов
/ 05 марта 2020

Вы можете просто передать и получить значение, как это.

// Creating and initializing an Intent object
Intent intent = new Intent(this, NextActivity.class);

// Attach the key value pair using putExtra to this intent
String pizza = "Margherita";
intent.putExtra("PIZZA_NAME", pizza);

// Start the activity
startActivity(intent);
// Get the current intent
Intent intent = getIntent();

// Get the attached extras from the intent
// We should use the same key as we used to attach the data.
String pizza = intent.getStringExtra("PIZZA_NAME");

0 голосов
/ 05 марта 2020

Удалить y = новое намерение (); в вашем bill.class

0 голосов
/ 05 марта 2020

Вам не нужно делать y= new Intent(); в Билле. java

Изменить код в Билле. java следующим образом. Кроме того, для лучшего соглашения об именах измените Bill. java на BillActivity. java

    TextView text1 = (TextView) findViewById(R.id.textView6);
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        String name = bundle.getString("name");
        text1.setText(name);
    }
...