How To Create App for Input a Value and Show it as a Toast message and in a Text box
Step 1) Create New Android Project With Empty Activity.
Step
2) Add a EditText,
a Button and TextView In Design mode To activity_main.xml
or Hardcode it .
activity_main.xml – Design mode
activity_main.xml – Text mode
Step 3) Program the App process in
MainActivity.java.
· Assign the Components.
· Click Event.
· Get Text , Set Text from EditText to TextView.
· Toast Message.
MainActivity.java
Code: 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.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn1 = findViewById(R.id.button1); final EditText editText=findViewById(R.id.editText); final TextView textView=findViewById(R.id.textView); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String inputtext=editText.getText().toString(); textView.setText(inputtext); Toast.makeText(MainActivity.this,inputtext , Toast.LENGTH_SHORT).show(); } }); }
}
Step 4 ) Run The App on a Android Phone Or in a AVD emulator.
Comments
Post a Comment