so what i am tring to do is, i am having a book like-app, and want to setup a button when click it change the textview to a string in the #string rec. but in a different way
i will put the code just a moment, lets say i have a string in #string that is NH1,NH2,NH3
i can do for button View.setText(R.string.NH1); that will work but i want to create a counter and make it so every time clicked counter++ and want it to be like this View.setText(R.string.NH+counter); if you know what i mean so each time it clicked to goes to next #string without changing layout every time and without an array because the paragraph are very long
also if i have NH1-10 and the counter did not stop and still goes on what will i do.
if you are sill here thank you for reading.
XML(sheetpaper)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="496dp"
android:background="#drawable/bg1"
android:gravity="top"
android:orientation="vertical"
android:weightSum="100" >
<Button
android:id="#+id/bPrev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="51dp"
android:background="#android:color/transparent"
android:text=" " />
<TextView
android:id="#+id/tvHadith"
android:layout_width="310dp"
android:layout_height="210dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="64dp"
android:text="#string/NH1"
android:textColor="#android:color/white" />
<Button
android:id="#+id/bNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/bPrev"
android:layout_alignBottom="#+id/bPrev"
android:layout_alignRight="#+id/tvHadith"
android:background="#android:color/transparent"
android:gravity="center"
android:text=" " />
"
</RelativeLayout>
</LinearLayout>
Java (Nawawi)
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Nawawi extends Activity {
private static final String NH = null;
Button Next;
Button Prev;
TextView View;
int counter = 0;
String H=NH;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sheetpaper);
Next = (Button) findViewById(R.id.bNext);
Prev = (Button) findViewById(R.id.bPrev);
View = (TextView) findViewById(R.id.tvHadith);
Next.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
counter++;
View.setText(R.string.H);
}
}); Prev.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
counter--;
View.setText(R.string.);
}
});
}
}
You could do this by creating an XML string array, so your strings will still be referenced in resources, but you'll be able to loop through them.
Something like this, in values/strings.xml:
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
</string-array>
And then in Activity:
Resources res = getResources();
final String[] planets = res.getStringArray(R.array.planets_array);
findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (counter < planets.length) {
textView.setText(planets[counter]);
counter++;
}
}
});
Be sure to check the counter against arrays length, otherwise you will get an IndexOutOfBoundsException.
Related
trying to run a fragment with a button and getting error after the execution:
Following this S.O. answer How to handle button clicks using the XML onClick within Fragments , but not working with me.
DetalhesFragment.java
package com.example.waitersoriginal;
import android.app.Fragment;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.TextView;
public class DetalhesFragment extends Fragment implements OnClickListener{
TextView nomeEntrada,descrEntrada,valorEntrada,nmArm,dsArm,vlArm;
String txtNome, txtDescr;
View view,v;
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.detalhes_fragment, container, false);
Button mButton = (Button) view.findViewById(R.id.button1);
nomeEntrada= (TextView) view.findViewById(R.id.textView1);
descrEntrada= (TextView)view.findViewById(R.id.textView2);
valorEntrada= (TextView)view.findViewById(R.id.textView3);
mButton.setOnClickListener((android.view.View.OnClickListener) this);
return view;
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button1:
PedidosFragment array = (PedidosFragment)getFragmentManager().findFragmentById(R.id.fragment3);
array.criaArray(txtNome,txtDescr);
break;
}
}
public void change(String txt, String txt1){
//public void change(String txt, String txt1, String txt2){
//public void change(String txt){
nomeEntrada.setText(txt);
descrEntrada.setText(txt1);
txtNome = txt;
txtDescr = txt1;
//valorEntrada.setText(txt2);
}
}
But this row contains errors:
public class DetalhesFragment extends Fragment implements OnClickListener{
Error: The type DetalhesFragment must implement the inherited abstract method DialogInterface.OnClickListener.onClick(DialogInterface,int)
I've tried to implement the method above, no success.
Can somebody help me with this?
Ty!
EDIT:
detalhes_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="14dp"
android:layout_y="14dp"
android:textSize="25dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="455dp"
android:layout_height="wrap_content"
android:layout_x="14dp"
android:layout_y="78dp"
android:textSize="18dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_x="285dp"
android:layout_y="19dp"
android:textSize="22dp" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="14dp"
android:layout_y="395dp"
android:text="Adicionar aos Pedidos"
android:visibility="visible" />
</AbsoluteLayout>
Remove this code:
mButton.setOnClickListener((android.view.View.OnClickListener) this);
return view;
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button1:
PedidosFragment array = (PedidosFragment)getFragmentManager().findFragmentById(R.id.fragment3);
array.criaArray(txtNome,txtDescr);
break;
}
}
Replace this code...
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button1:
PedidosFragment array = (PedidosFragment)getFragmentManager().findFragmentById(R.id.fragment3);
array.criaArray(txtNome,txtDescr);
break;
}
});
return view;
}
As the error says your have to implement (add in your class) a method with the name onClick with a parameter of type DialogInterface and another one of type int.
That is because your are implementing an interface which is a kind of contract. All methods of the interface you implement it is mandatory to you to create it on your class even if it has no code at all.
Like:
#Override
public void onClick(DialogInterface dialogInterface, int i){}
EDIT
Sorry, I just saw your code and see the the method is there what you need to do is to add the right parameters. Right now you are passing just a view.
Can you use Linear Layout.
Why did use absolute layout?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" ><TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="14dp"
android:layout_y="14dp"
android:textSize="25dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="455dp"
android:layout_height="wrap_content"
android:layout_x="14dp"
android:layout_y="78dp"
android:textSize="18dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_x="285dp"
android:layout_y="19dp"
android:textSize="22dp" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="14dp"
android:layout_y="395dp"
android:text="Adicionar aos Pedidos"
android:visibility="visible" />
</LinearLayout>`
Can You try this...
i can't figure why my toast dosen't show up anyone can help ... i started today to learn app development but i don't understand what is the problem...
My app works without any error , this is a work exercise from my programming book
package com.example.geoquiz;
import android.widget.Button;
import android.widget.Toast;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
public class QuizActivity extends Activity {
private Button but1;
private Button but2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
but1 = (Button) findViewById(R.id.true_button);
but1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(QuizActivity.this,R.string.correct_toast, Toast.LENGTH_SHORT).show();
}
});
but2 = (Button) findViewById(R.id.false_button);
but2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(QuizActivity.this, R.string.incorect_toast, Toast.LENGTH_SHORT).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.quiz, menu);
return true;
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:text="#string/question_text" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/true_button"
android:id ="#+id/true_button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/false_button"
android:id ="#+id/false_button" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">GeoQuiz</string>
<string name="hello_world">Hello world!</string>
<string name ="question_text">Gabriel este un baiat destept ?</string>
<string name ="true_button">TRUE</string>
<string name ="false_button">FALSE</string>
<string name ="action_settings">Settings</string>
<string name ="correct_toast">RaspunsCorect</string>
<string name ="incorect_toast">RaspunsIncorect</string>
</resources>
Try this. Go into your xml and on the button you want to make the toast text add
android:onClick="ToastButtonClicked" />
^ into it.
Then use the below code for making the toast text.
}
public void ToastButtonClicked(View view)
{
Toast.makeText(this,R.string.correct_toast, Toast.LENGTH_SHORT).show();
}
Try replacing
Toast.makeText(QuizActivity.this,R.string.correct_toast, Toast.LENGTH_SHORT).show();
with
Toast.makeText(getApplicationContext(),R.string.correct_toast, Toast.LENGTH_SHORT).show();
replace this
Toast.makeText(QuizActivity.this,R.string.correct_toast, Toast.LENGTH_SHORT).show();
with
Toast.makeText(QuizActivity.this,"Correct Toast", Toast.LENGTH_SHORT).show();
may be it will help you
Iam doing an android application. In that i want to create dynamic controls(edittext) like android core contacts application. After entering data in the ediitext i want to save the data to sqlite database by clicking a button named save. As Iam new to android i dont have any idea to create dynamic controls and storing its row values. Please help me if anybody knows.
My code:
package com.xiaochaoyang.dynamicviews;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
// Parent view for all rows and the add button.
private LinearLayout mContainerView;
// The "Add new" button
private Button mAddButton;
// There always should be only one empty row, other empty rows will
// be removed.
private View mExclusiveEmptyView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.row_container);
mContainerView = (LinearLayout) findViewById(R.id.parentView);
mAddButton = (Button) findViewById(R.id.btnAddNewItem);
// Add some examples
inflateEditRow("Xiaochao");
inflateEditRow("Yang");
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// TODO: Handle screen rotation:
// encapsulate information in a parcelable object, and save it
// into the state bundle.
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// TODO: Handle screen rotation:
// restore the saved items and inflate each one with inflateEditRow;
}
// onClick handler for the "Add new" button;
public void onAddNewClicked(View v) {
// Inflate a new row and hide the button self.
inflateEditRow(null);
//v.setVisibility(View.GONE);
}
// onClick handler for the "X" button of each row
public void onDeleteClicked(View v) {
// remove the row by calling the getParent on button
mContainerView.removeView((View) v.getParent());
}
// Helper for inflating a row
private void inflateEditRow(String name) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.row, null);
final ImageButton deleteButton = (ImageButton) rowView
.findViewById(R.id.buttonDelete);
final EditText editText = (EditText) rowView
.findViewById(R.id.editText);
if (name != null && !name.isEmpty()) {
editText.setText(name);
} else {
mExclusiveEmptyView = rowView;
//deleteButton.setVisibility(View.INVISIBLE);
}
// A TextWatcher to control the visibility of the "Add new" button and
// handle the exclusive empty view.
editText.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable s) {
if (s.toString().isEmpty()) {
//mAddButton.setVisibility(View.GONE);
//deleteButton.setVisibility(View.INVISIBLE);
if (mExclusiveEmptyView != null
&& mExclusiveEmptyView != rowView) {
mContainerView.removeView(mExclusiveEmptyView);
}
mExclusiveEmptyView = rowView;
} else {
if (mExclusiveEmptyView == rowView) {
mExclusiveEmptyView = null;
}
mAddButton.setVisibility(View.VISIBLE);
deleteButton.setVisibility(View.VISIBLE);
}
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
// Inflate at the end of all rows but before the "Add new" button
mContainerView.addView(rowView, mContainerView.getChildCount() );
}
}
My layouts:
Row Cointainer.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parentView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical" >
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btnAddNewItem"
android:layout_width="21dp"
android:layout_height="wrap_content"
android:background="#drawable/transparent_background"
android:gravity="center_vertical"
android:onClick="onAddNewClicked"
android:layout_gravity="right"
android:paddingLeft="5dp"
android:text="+"
android:textColor="#android:color/black" />
</ScrollView>
</LinearLayout>
Row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<EditText
android:id="#+id/editText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:singleLine="true"
android:ems="10"
android:hint="" >
<requestFocus />
</EditText>
<Spinner
android:id="#+id/spinnerCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.15"
android:entries="#array/categories"
android:gravity="right" />
<ImageButton
android:id="#+id/buttonDelete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/content_remove"
android:background="#drawable/transparent_background"
android:contentDescription="#string/button_delete_row_description"
android:onClick="onDeleteClicked"/>
</LinearLayout>
First of all, while posting your question in SO, please show what have you tried so far, post your logcat if your app is getting force closed.
To work with controls, please refer to http://developer.android.com/reference/packages.html
There you find the methods available to work with controls.
Check this link: http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
It helps to learn and perform CRUD operations on SQLite Database.
At last, what you left with is, get data (or input) from controls, and insert into database.
Also, please go for googling.
I am new to Android. I am trying to get input from the EditText and displaying it in TextView with the help of button. When I click the button nothing happens. Please help, here is my MainActivity.java code -
package com.example.addname;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
Button b1;
TextView v1;
EditText t1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button1);
t1 = (EditText) findViewById(R.id.editText1);
v1 = (TextView) findViewById(R.id.textView1);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(t1.getText().toString()=="")
{
v1.setText(t1.getText().toString());
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
and here is my activity_main.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"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="25dp"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView1"
android:layout_below="#+id/editText1"
android:layout_marginTop="48dp"
android:text="Button" />
</RelativeLayout>
Instead of
if(t1.getText().toString()=="")
{
v1.setText(t1.getText().toString());
}
You can use
if(t1.getText().isEmpty()) // isEmpty() is only available from API 9 and Above
{
v1.setText(t1.getText().toString());
}
or this
if(t1.getText().trim().length == 0)
{
v1.setText(t1.getText().toString());
}
Don't compare strings using ==. You're actually comparing reference of an object. To compare strings, use equals() method.
I'd recommend comparing strings with .equals() since Objects compared with == usually fails (== compares references, not Object content).
if(t1.getText().toString().equals("")))
in your case though,since you're comparing an empty String, you can also use
if (t1.getText().toString().length == 0)
Then note that once you set the text, you're setting v1's text to an empty string since your logic indicates that only upon an empty string you set v1's text. So I'd recommend getting rid of the if altogether:
#Override
public void onClick(View arg0) {
v1.setText(t1.getText().toString());
}
I've created this simple example to illustrate what i am trying to accomplish.
This is my first layout:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class LifeCycleActivity extends Activity implements OnCheckedChangeListener {
/** Called when the activity is first created. */
private RadioButton rbR, rbG, rbB;
private RadioGroup rg;
private Button next;
int color=0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
rbR = (RadioButton) findViewById(R.id.radio0);
rbB = (RadioButton) findViewById(R.id.radio1);
rbG = (RadioButton) findViewById(R.id.radio2);
rg = (RadioGroup) findViewById(R.id.radioGroup1);
next = (Button) findViewById(R.id.button1);
final Intent it = new Intent(this, next.class);
final Bundle b = new Bundle();
rg.setOnCheckedChangeListener(this);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
b.putInt("color", color);
it.putExtras(b);
startActivity(it);
}
});
}
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if (checkedId==rbR.getId()) color=1;
if (checkedId==rbB.getId()) color=2;
if (checkedId==rbG.getId()) color=3;
}
}
This is the second layout:
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.*;
public class next extends Activity {
private LinearLayout ll;
private ImageView im;
private TextView tv;
private Button save;
private Bundle extras;
private int color=0;
private String selColor="";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.next);
ll = (LinearLayout) findViewById(R.id.mainll);
ll.setOrientation(LinearLayout.VERTICAL);
im = new ImageView(this);
tv = new TextView(this);
save = new Button(this);
save.setText("save");
extras = getIntent().getExtras();
color = extras.getInt("color");
im.setImageResource(R.drawable.ic_launcher);
ll.addView(im);
if (color == 1) selColor = "RED";
if (color == 2) selColor = "BLUE";
if (color == 3) selColor = "GREEN";
tv.setText(selColor);
tv.setGravity(Gravity.CENTER);
ll.addView(tv);
ll.addView(save);
save.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
// here i want to save and exit
// so i can call onPause(), then finish()
// do not know how exactly since i have to follow some goals
// that i need for this example
}
});
}
}
I also have main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="red" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="blue" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="green" />
</RadioGroup>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next" />
</LinearLayout>
AND next.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
As you can see, based on color selection in first layout I dynamically build the second layout.
This is what I want to do, help me please (add code if possible):
on the second layout if I press save, I want to save app state (whatever I built on that page) and exit.
If I add one more button to create other dynamic objects on that layout (EditText with name, or another layout with different objects) than if user saves, he/she will also save new objects (This part can be done later)
if user saved that page once then i want him to be able to get the same app state that he/she was in before exiting (of course if he/she selects the same radio button).
If he/she selects another button, i do not need to show that previous state, since the selection is different.
The trick with sharedpreferences did for me. I was finally able to same and retrieve my data onPause and onStart. Even though this worked fine, I appreciate the answer of Kevin_Dingo which is defiantly more professional way to go.