Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialWejdan Al Mubarky
Courses Plus Student 1,451 PointsThe %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
6,111 Pointstry %1$s instead, you're missing an 's' you haven't really defined that you want it to be a simple string
Seth Kroger
56,413 PointsSeth Kroger
56,413 PointsCode?