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:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Large Text" android:id="@+id/textView" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="41dp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show" android:id="@+id/button" android:layout_below="@+id/textView" android:layout_centerHorizontal="true" android:layout_marginTop="77dp" /> </RelativeLayout>
MainActivity.Java
------------------
package com.android.anil.textview; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity { TextView t1; Button b1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1=(Button)findViewById(R.id.button); t1=(TextView)findViewById(R.id.textView); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String s1="Hi Android"; t1.setText(s1); } }); } }
Output is :
-------------
No comments:
Post a Comment