0% found this document useful (0 votes)
20 views

Package Import Import Import Import Import Import Import Public Class Extends

This Android code defines a MainActivity class that displays an edit text field and button. When the button is clicked, it gets the text from the edit text and displays it in a toast popup. The activity layout XML defines the edit text and button widgets with their IDs so they can be referenced in the activity class code.

Uploaded by

ilias ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Package Import Import Import Import Import Import Import Public Class Extends

This Android code defines a MainActivity class that displays an edit text field and button. When the button is clicked, it gets the text from the edit text and displays it in a toast popup. The activity layout XML defines the edit text and button widgets with their IDs so they can be referenced in the activity class code.

Uploaded by

ilias ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

package com.example.androidapps.

myapplication1;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText etfTest ;
Button BtClick;
String text;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

BtClick=findViewById(R.id.BtClick);
etfTest=findViewById(R.id.etfTest);

BtClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text=etfTest.getText().toString();
Toast.makeText(MainActivity.this,text,Toast.LENGTH_SHORT).show();
}
});

activitylayout.xml

<EditText
android:id="@+id/etfTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BtClick"
android:textsize="30sp"
android:id="@+id/BtClick"
android:layout_below="@+id/e
Practice class android make by ilias ahmed

You might also like