DIỄN ĐÀN TIN HOC
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.
DIỄN ĐÀN TIN HOC

BÀI VIẾT MỚINGƯỜI GỬI CUỐI

      Thảo luận nhiều nhất

      Lượt xem nhiều nhất


      You are not connected. Please login or register

      [Android] Switch

         

      nhuvannhu

      #1[Android] Switch Empty Thu May 29, 2014 11:20 am

      nhuvannhu
      nhuvannhu Quản lý viên

      Giới tính : Nam

      Tổng số bài gửi Tổng số bài gửi : 18

      Points Points : 57

      Like Like : 3

      status : Không có gì để nói

      Project demo[You must be registered and logged in to see this link.]
      Yêu cầu android:minSdkVersion="14"
      [Android] Switch Vxh5QlX
      ActivitySwitch.java
      Code:
      import android.os.Bundle;
      import android.app.Activity;
      import android.content.Intent;
      import android.view.Menu;
      import android.widget.CompoundButton;
      import android.widget.Switch;
      import android.widget.CompoundButton.OnCheckedChangeListener;

      public class ActivitySwitch extends Activity {
         private Switch switch1;
         

         @Override
         protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_switch);
            switch1 = (Switch) findViewById(R.id.switch1);
            switch1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
               
               @Override
               public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
               
                  // TODO Auto-generated method stub
                  if(arg1 == true){
                     Intent intent = new  Intent(ActivitySwitch.this,ActivitySwitch2.class);
                     startActivity(intent);
                  }
                  else {
                     
                  }
               }
            });
         }



      }
      ActivitySwitch2.java
      Spoiler:
      activity_switch.xml
      Code:
      <LinearLayout 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"
          android:gravity="center"
          android:orientation="vertical"
          tools:context=".Demochuabiet" >
         <TextView android:text=" Bạn muốn chuyển activity"
             android:layout_height="50dp"
             android:layout_width="100dp"/>
          <Switch
              android:id="@+id/switch1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textOn="Ukm"
              android:textOff="Không"
         
            />

      </LinearLayout>
      activity_switch2.xml
      Spoiler:
         
            

      [Trang 1 trong tổng số 1 trang]

      Thông tin chuyên mục

      Bạn không có quyền trả lời bài viết