I am making an Facts based application. I want it to show new fact every time the user presses the button and i also want that when the user exits the app and restart it, it would resume from the same fact that user was reading. Help me guys... I have included the java and xml code that i am using Thanks in advance
My Java Layout
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Next(View view) {
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("Hi");
textView.setText("No One is here to sleep");
textView.setText("This sounds like fun");
textView.setText("Men will be men");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
// present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
// noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Xml:
<RelativeLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#ff7922ff">
<TextView android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:textSize="35dp"
android:layout_above="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="106dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="@+id/button"
android:layout_marginBottom="158dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="Next" />
</RelativeLayout>