လဵပ်ႈႁဵၼ်း Android Studio 001 ( Toast Message + Click Button)
main.xml code
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Main"> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Click" /> </LinearLayout>
Main java code
package com.example.jaotainum.toast; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class Main extends AppCompatActivity { Button test; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); test= (Button) findViewById(R.id.btn); test.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(Main.this, "Hello", Toast.LENGTH_SHORT).show(); } }); } public void dosomthing(View v) { } }
No comments:
Post a Comment