如何永久更改文本 [英] How Do I Change Text Permanently

查看:62
本文介绍了如何永久更改文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生我在android和一个文本字段中创建了一个按钮。当我单击按钮时,文本字段中的文本创建到按钮但是当我重新启动模拟器或应用程序时,更改不起作用,它显示第一个原始文本。例如按钮的第一个文本是第一个,当我单击按钮,文本通过文本字段更改为second.so当我重新启动模拟器或应用程序时,它首先显示文本而不是第二个。所以请给出一个简单的示例,用代码创建在android中永久更改。





xml代码为



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

<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

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]已添加代码块 - OriginalGriff [/ edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

您无法永久更改它。代码是代码。如果您需要不同的文本,则需要通过实施更改来重建应用程序。
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.


这篇关于如何永久更改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆