• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Editing TextView from EditText on Button click

Hey guys, new to the forum :)

I had a question on a piece of my code..

What I'm trying to do is learn how to set a TextView's default text to whatever I edit in the EditText

In Lamence terms..

Default Text <---Label
[Default Text] <---Text Box
[Change] <---Button

If I change the information in the Text Box, it will change the Label on the Change Button click..

Now, it will change the text to 'false' and I can't figure out what I'm doing wrong..

Here's my Main.java:

Code:
package com.testapp.android;

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

public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        changeButton = (Button)findViewById(R.id.change);
        changeButton.setOnClickListener(new OnClickListener()
        {
        	@Override
        	public void onClick(View v)
        	{
        		changeLabel = (TextView)findViewById(R.id.label);
        		changeLabel.setText(R.id.textField);
        	}
        });
    }
    public Button changeButton;
    public TextView changeLabel;
}

and here's my main.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
	android:id="@+id/label"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Default"
    />
<EditText
	android:id="@+id/textField"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:text="Default"/>
<Button
	android:id="@+id/change"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="Change"/>
</LinearLayout>

Thanks a bunch guys :) If you have any questions on what I'm trying to do feel free to question, I know it's kinda hard to understand with my ASCII drawing :p..
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones