<SlidingDrawer android:id="@+id/slidingDrawer1" android:layout_width="match_parent" android:layout_height="wrap_content" > </SlidingDrawer>
<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" > <SlidingDrawer android:id="@+id/slidingDrawer1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:content="@+id/content" android:handle="@+id/btnSlide1" > <Button android:id="@+id/btnSlide1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Slide Up" /> <LinearLayout android:id="@+id/content" android:orientation="vertical" android:gravity="center" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 2" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 3" /> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 4" /> </LinearLayout> </SlidingDrawer> </RelativeLayout>
package com.myapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.SlidingDrawer; import android.widget.SlidingDrawer.OnDrawerCloseListener; import android.widget.SlidingDrawer.OnDrawerOpenListener; import android.app.AlertDialog; public class MainActivity extends Activity { Button btnSlide; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnSlide = (Button) findViewById(R.id.btnSlide1); SlidingDrawer SlidingD = (SlidingDrawer) findViewById(R.id.slidingDrawer1); SlidingD.setOnDrawerOpenListener(new OnDrawerOpenListener() { public void onDrawerOpened() { btnSlide.setText("Slide Down"); } }); SlidingD.setOnDrawerCloseListener(new OnDrawerCloseListener() { public void onDrawerClosed() { btnSlide.setText("Slide Up"); } }); // Event for Button final AlertDialog.Builder adb = new AlertDialog.Builder(this); Button btn1 = (Button) findViewById(R.id.button1); btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { AlertDialog ad = adb.create(); ad.setMessage("Button 1 Event"); ad.show(); } }); Button btn2 = (Button) findViewById(R.id.button2); btn2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { AlertDialog ad = adb.create(); ad.setMessage("Button 2 Event"); ad.show(); } }); Button btn3 = (Button) findViewById(R.id.button3); Button btn4 = (Button) findViewById(R.id.button4); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
package com.myapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.SlidingDrawer; import android.widget.SlidingDrawer.OnDrawerCloseListener; import android.widget.SlidingDrawer.OnDrawerOpenListener; import android.app.AlertDialog; public class MainActivity extends Activity implements OnClickListener { Button btnSlide; Button btn1,btn2,btn3,btn4; AlertDialog.Builder adb; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnSlide = (Button) findViewById(R.id.btnSlide1); SlidingDrawer SlidingD = (SlidingDrawer) findViewById(R.id.slidingDrawer1); SlidingD.setOnDrawerOpenListener(new OnDrawerOpenListener() { public void onDrawerOpened() { btnSlide.setText("Slide Down"); } }); SlidingD.setOnDrawerCloseListener(new OnDrawerCloseListener() { public void onDrawerClosed() { btnSlide.setText("Slide Up"); } }); // Event for Button adb = new AlertDialog.Builder(this); btn1 = (Button) findViewById(R.id.button1); btn2 = (Button) findViewById(R.id.button2); btn3 = (Button) findViewById(R.id.button3); btn4 = (Button) findViewById(R.id.button4); btn1.setOnClickListener(this); btn2.setOnClickListener(this); btn3.setOnClickListener(this); btn4.setOnClickListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } public void onClick(View v) { // TODO Auto-generated method stub Button b = (Button)v; AlertDialog ad = adb.create(); ad.setMessage("Your Click : " + b.getText()); ad.show(); } }
public void onClick(View v) { // TODO Auto-generated method stub Button b = (Button)v; AlertDialog ad = adb.create(); ad.setMessage("Your Click : " + b.getText()); ad.show(); }
public void onClick(View v) { // TODO Auto-generated method stub Button b = (Button)v; String action = b.getText(); if ("Button 1".equals(action)) { // Event Button 1 } else if ("Button 2".equals(action)) { // Event Button 2 } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท