Android Build an Interactive Story App Finishing the User Interface Formatting Strings

Wejdan Al Mubarky
PRO
Wejdan Al Mubarky
Pro Student 1,451 Points

The %1$ appears in the app as it is. It doesn't change!

when I run the app my name doesn't show on the screen it remains %1$ and I don't know why! this is my StoryActivity class:

package com.example.asus.interactivestory.ui;

import android.content.Intent;

import android.graphics.drawable.Drawable;

import android.support.v4.content.ContextCompat;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.util.Log;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.TextView;

import com.example.asus.interactivestory.R;

import com.example.asus.interactivestory.model.page;

import com.example.asus.interactivestory.model.Story;

public class StoryActivity extends AppCompatActivity {

public static final String TAG= StoryActivity.class.getSimpleName();

private String name;

private Story story;

private ImageView StoryImageView;

private TextView textView;

private Button choice1Button;

private Button choice2Buutton;

@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_story);

    StoryImageView = (ImageView) findViewById(R.id.StoryImageView);

    textView = (TextView)findViewById(R.id.textView);

    choice1Button = (Button)findViewById(R.id.choice1Button);

    choice2Buutton = (Button)findViewById(R.id.choice2Buutton);

    Intent intent = getIntent();

     name = intent.getStringExtra(getString(R.string.Key_name));

    if( name == null || name.isEmpty()){

        name="Friend";}

    Log.d(TAG,name);

    story= new Story();

    loadPage(0);
}

private void loadPage(int pageNumber) {

   page pagee = story.getPage(pageNumber);

   Drawable image = ContextCompat.getDrawable(this, pagee.getImageId() );

  StoryImageView.setImageDrawable(image);

   String pageText = getString(pagee.getTextId());

   String.format(pageText,name);

   textView.setText(pageText);

   choice1Button.setText(pagee.getChoice1().getTextId());

   choice2Buutton.setText(pagee.getChoice2().getTextId());

}

}

1 Answer

Ashraf Rahman
Ashraf Rahman
6,111 Points

try %1$s instead, you're missing an 's' you haven't really defined that you want it to be a simple string