I am going to add HTML code in each time in the textview, for that I have written my paragraph in my string.xml
file and taken that every thing to story.java
file, then I added one textview
to show that text.
I don't know if it will work or not. So,first of all Is this a correct logic? If correct then, I am getting Null pointer error
.
Please give solution to solve this.
This is my Story.java
file.
@SuppressWarnings("deprecation")
public class story extends AppCompatActivity {
Button next;
Button prev;
TextView t;
int count=0;
int[] stories = {
R.string.firststory,
R.string.story2,
R.string.story3,
R.string.story4,
R.string.story5,
R.string.story6,
R.string.story7,
R.string.story8,
R.string.story9,
R.string.story10,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.story);
next = (Button) this.findViewById(R.id.next);
prev = (Button) this.findViewById(R.id.prev);
t = (TextView) this.findViewById(R.id.textview);
t.setText(Html.fromHtml(getString(stories[0])));
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
count=count+1;
if(count<=10) {
t.setText(Html.fromHtml(getString(stories[count])));
}
else
{
Toast toast=Toast.makeText(getApplicationContext(),"This is Last story",Toast.LENGTH_SHORT);
}
}
});
prev.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
count=count-1;
if(count>=0)
{
t.setText(Html.fromHtml(getString(stories[count])));
}
else{
Toast toast=Toast.makeText(getApplicationContext(),"This is first story",Toast.LENGTH_SHORT);
}
}
});
}
}
And this is my story.xml
file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2" />
<Button
android:text="previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/prev"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:text="next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/next"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>