Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir i created a button in android and one text field.when i click the button the text in the textfield created to the button but when i relaunch the emulator or app the change doesnot effect it show the first origional text.for example the first text to the button is first when i click the button and the text changed through the textfield as second.so when i relaunch the emulator or app it show the text first not second.so kindly give a simple example with code to create the change permanently in android.


xml code as

HTML
<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <edittext>
        android:id="@+id/edit11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="50dp"
        android:layout_marginTop="23dp"
        android:ems="10" >

        <requestfocus />
    </edittext>

    <Button
        android:id="@+id/button11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/edit11"
        android:layout_below="@+id/edit11"
        android:layout_marginTop="62dp"
        android:text="text changed" />

</relativelayout>

and main code as
Java
package com.example.first;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		final Button changed=(Button)findViewById(R.id.button11);
		final EditText text=(EditText)findViewById(R.id.edit11);
		 
		changed.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				
				changed.setText(text.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.main, menu);
		return true;
	}

}


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 25-Jun-15 19:29pm
v2
Comments
OriginalGriff 26-Jun-15 1:29am    
Do not repost your question to add information: use the "Improve question" widget instead. I'll delete the older one this time (normally I delete the newer version) as you have added code - but that needs to be in code blocks to preserve the formatting. (I've sorted that out for you as well).

1 solution

You cannot change it permanently. The code is the code. If you want different text then you need to rebuild the app with the change implemented.
 
Share this answer
 
Comments
wajib rehman 26-Jun-15 23:35pm    
actually i have created a hotel home delivery app.so there is a setting button .so when the hotel focal person want to change the menu for example in the menu there is a meat so he want to replace the meat with rice in the menu of hotel .so then how is it possible how to change ,replace the one item of the menu with other one
Richard MacCutchan 27-Jun-15 3:56am    
You need to set up some sort of configuration file (XML would be a good choice), that contains all the item names. Then when the app starts it reads the items from the file and uses them to set the text of buttons and menus.
wajib rehman 29-Jun-15 0:11am    
how to replace radiobutton by another radiobutton dynamically in android
Richard MacCutchan 29-Jun-15 3:23am    
Sorry I don't understand what you mean. If you have a radiobutton in your view why would you need to replace it?
wajib rehman 29-Jun-15 5:38am    
sir i have created a hotel food menu ;
in the menu there are more items like meat,vegetable,rice etc and these are libeled with radiobutton.so a hotel focal person want to change the menu by pressing the setting button and he want to replace the menu item 'meat' with 'cool drinks' so this how can possible to replace the radiobutton with another radio button.plzz help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900