1. 程式人生 > >android 點選按鈕實現頁面跳轉並顯示以選擇資訊

android 點選按鈕實現頁面跳轉並顯示以選擇資訊

感覺今天所學的 radio listcheckbox spinner 基礎內容都比較簡單

目前只寫了單選的資訊顯示。

checkBox 和 Spinner 還沒實現

原始碼如下

(注意要寫第二個Activity的清單

即新增Activity02的activity標籤)

Activity01Activity

package yzy.cxt.com;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;


public class Activity01Activity extends Activity {


// 定義控制元件變數
private RadioButton radioButton01;
private RadioButton radioButton02;
private CheckBox cb1;
private CheckBox cb2;
private CheckBox cb3;
private CheckBox cb4;
private EditText editText;
private Button button;
 


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.one_layout);


// 繫結變數
radioButton01 = (RadioButton) findViewById(R.id.radiobutton01);
radioButton02 = (RadioButton) findViewById(R.id.radiobutton02);
cb1 = (CheckBox) findViewById(R.id.cb1);
cb2 = (CheckBox) findViewById(R.id.cb2);
cb3 = (CheckBox) findViewById(R.id.cb3);
cb4 = (CheckBox) findViewById(R.id.cb4);
editText = (EditText) findViewById(R.id.edit);
button = (Button) findViewById(R.id.button);


// 為radioButton01設定監聽事件
radioButton01.setOnCheckedChangeListener(new OnCheckedChangeListener() {


@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
radioButton01.setChecked(isChecked);
if (radioButton02.isChecked()) {
radioButton02.setChecked(false);
}
}


});


// 為radioButton02設定監聽事件
radioButton02.setOnCheckedChangeListener(new OnCheckedChangeListener() {


@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
radioButton02.setChecked(isChecked);
if (radioButton01.isChecked()) {
radioButton01.setChecked(false);
}
}


});
 
 
// 為Button設定監聽事件
button.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View arg0) {
String quantityType = "";
String descri = "";
String db = "";
// 獲取資訊
if (radioButton01.isChecked() && !radioButton02.isChecked()) {
quantityType = "twenty";
} else if (radioButton02.isChecked()
&& !radioButton01.isChecked()) {
quantityType = "thirty";
} else {
Toast.makeText(Activity01Activity.this, "請正確選擇",
Toast.LENGTH_LONG);
}




descri = editText.getText().toString();


// 將資訊放入Bundle
Bundle bundle = new Bundle();
bundle.putString("quantityType", quantityType);
bundle.putString("desc", descri);
 


Intent intent = new Intent();
intent.setClass(Activity01Activity.this, Activity02.class);
intent.putExtras(bundle);


// 開始。。。。跳轉
startActivity(intent);
}


});
}

}

Activity02

package yzy.cxt.com;


import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;


public class Activity02 extends Activity{


 private TextView message;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.two_layout);
  
  Bundle bundle = this.getIntent().getExtras();
  String quantity = "";
  // 接收資訊並顯示
  message = (TextView)findViewById(R.id.message);
  String quantityType = bundle.getString("quantityType");
  String desc = bundle.getString("desc");
  
  // 判斷
  if ("twenty".equals(quantityType)) {
 quantity = "20";
  } else {
 quantity = "30";
  }
  
  message.setText("你選擇的每頁帖數是" + quantity + ", 您對本站的看法為:" + desc);
 }


}
one_layout


<?xml version="1.0" encoding="utf-8"?> 


<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
    Android:orientation="vertical"
    Android:layout_width="fill_parent"
    Android:layout_height="fill_parent"
    >
     <TextView
            Android:layout_width="fill_parent"
            Android:layout_height="wrap_content"
            Android:text="介面風格"
            Android:textSize="20px" />


        <Spinner
            Android:id="@+id/styleSp"
            Android:layout_width="fill_parent"
            Android:layout_height="wrap_content"
            Android:entries="@array/style"
            Android:prompt="@string/style_prompt" />
    <TextView
            Android:layout_width="fill_parent"
            Android:layout_height="wrap_content"
            Android:text="提醒"
            Android:textSize="20px" />


        <CheckBox
            Android:id="@+id/cb1"
            Android:layout_width="fill_parent"
            Android:layout_height="wrap_content"
            Android:text="私人訊息" />
              <CheckBox
            Android:id="@+id/cb2"
           Android:layout_width="fill_parent"
            Android:layout_height="wrap_content"
            Android:text="公共訊息" />
                    <CheckBox
            Android:id="@+id/cb3"
            Android:layout_width="fill_parent"
            Android:layout_height="wrap_content"
            Android:text="論壇任務" />
                          <CheckBox
            Android:id="@+id/cb4"
            Android:layout_width="fill_parent"
            Android:layout_height="wrap_content" 
            Android:text="系統訊息"/>
 <TextView  
     Android:layout_width="wrap_content" 
     Android:layout_height="wrap_content" 
     Android:textSize="20sp"
     Android:layout_marginLeft="30px"
     Android:layout_marginRight="30px"
     Android:text="每頁帖數"
    />  
    <RadioButton
     Android:id="@+id/radiobutton01"
     Android:layout_width="wrap_content"
     Android:layout_height="wrap_content"
     Android:text="20"
    />
    <RadioButton
     Android:id="@+id/radiobutton02"
     Android:layout_width="wrap_content"
     Android:layout_height="wrap_content"
     Android:text="30"
    />
    <TextView  
     Android:layout_width="wrap_content" 
     Android:layout_height="wrap_content" 
     Android:textSize="20sp"
     Android:text="您對本站的看法"
    />  
    <EditText  
  Android:id="@+id/edit"
     Android:layout_width="wrap_content" 
     Android:layout_height="wrap_content" 
     Android:textSize="20px"
     Android:width="200sp"
    />
    <Button
  Android:id="@+id/button"
     Android:layout_width="wrap_content" 
     Android:layout_height="wrap_content" 
     Android:text="提交"
    />
</LinearLayout>

two_layout

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
    Android:orientation="vertical"
    Android:layout_width="fill_parent"
    Android:layout_height="fill_parent"
    >
 <TextView  
  Android:id="@+id/message"
     Android:layout_width="wrap_content" 
     Android:layout_height="wrap_content" 
    />  
</LinearLayout>




相關推薦

android 按鈕實現頁面顯示選擇資訊

感覺今天所學的 radio listcheckbox spinner 基礎內容都比較簡單 目前只寫了單選的資訊顯示。checkBox 和 Spinner 還沒實現 原始碼如下 (注意要寫第二個Activity的清單 即新增Activity02的activity標籤)

微信小程式例子——文字實現頁面

1、效果展示 .w 2、關鍵程式碼 index.js檔案 Page({ data:{ // text:"這是一個頁面" }, onLoad:function(options){

Button事件實現頁面的兩種方法

方法一: 常用方式,在java檔案中給Button設定點選監聽事件button.setOnClickListener(),新建Intent類,從MainActivity跳轉至ImageTest but

web頁面按鈕喚起App到指定頁面以及返回鍵的處理

1.在需要跳轉的指定頁面的AndroidManifest中配置 <activity android:name=".activity.goods.GoodsDetail" android:configChanges="keyboardHidden|ori

使用 Qt Designer建立前端介面,通過VS Code將Qt Designer建立好的.ui轉換為.py,最後使用PyQt5實現按鈕介面發生

簡單的提一下PyQt5,Qt Designer的安裝 python 版本:3.6.2 使用pip安裝: pip3 install PyQt5 之後通過安裝PyQt5-tools,會自動安裝Qt Designer pip install PyQt

Android 按鈕實現控制元件顯示隱藏

我寫了一個自定義的listview,listview 每一列點選切換圖示 同時顯示 隱藏的佈局,再次點選則隱藏該佈局。以下是判斷的程式碼: holder.isShowlin.setOnClickListener(new View.OnClickListener() { @

android 分享的連結到應用程式

我們時常會遇到這種需求,點選一個連結跳轉到我們的應用程式當中。 (點選一個連結跳轉到一個下載apk的html,這是沒有安裝這個apk的情況,如果安裝了可以直接跳轉到我們的apk應用當中) 如果需要帶入資料過去只需在連結的網址上加入引數即可例如: <a href="ht

js+css控制彈出小視窗之後,後整個頁面背景圖變色,並且不可操作,確定,頁面。。。

<html> <head> <title>彈出一個視窗後,後面的層不可操作 ,點選確定之後跳轉新的頁面</title> <script> function show() //顯示隱藏層和彈出層 {

AngularJS進階 八 實現頁面進行參數傳遞

res 初始化 .get web js進階 頁面 city 過程 元素 angularjs實現頁面跳轉並進行參數傳遞 註:請點擊此處進行充電! Angular頁面傳參有多種辦法,我在此列舉4種最常見的: 1. 基於ui-router的頁面跳轉傳參 (1) 在Angular

AngularJS進階 八 實現頁面進行引數傳遞

angularjs實現頁面跳轉並進行引數傳遞 注:請點選此處進行充電! Angular頁面傳參有多種辦法,我在此列舉4種最常見的: 1. 基於ui-router的頁面跳轉傳參 (1) 在AngularJS的app.js中用ui-router定義路由,比如現在

angularjs實現頁面進行引數傳遞

Angular頁面傳參有多種辦法,我在此列舉4種最常見的: 1. 基於ui-router的頁面跳轉傳參 (1) 在AngularJS的app.js中用ui-router定義路由,比如現在有兩個頁面,一個頁面(producers.html)放置了多個producers,點選其

利用js實現頁面到的頁面進行判斷操作

1、跳轉按鈕頁面 可以在a標籤上直接寫上跳轉的地址,這裡要注意的是url後面要接上我們傳到下個頁面的引數,這樣才能在下個頁面利用js解析url並進行判斷。 <a href="123.html?

android中怎麼實現按鈕進行頁面

第一步:先建立好兩個Activity。如圖(PS:是建立Activity,不是建立java類。右擊包名,找到new-->other-->android-->AndroidActivity。然後根據提示完成Activity的建立。系統會自動建立好兩個Activ

Android實現ListView顯示資訊每個item,到相應介面

介面如下:(做這個目的僅僅是為了學習一點小知識,因為自己才剛開始) 實現的方法比較簡單,就是定義一個ListView,然後設定監聽,ListView對每個條目的監聽是setOnItemClickListener。 onItemClick(AdapterView&

Android按鈕到網頁

<Button android:layout_width="60dp" android:layout_height="40dp" android:onClick="tiaowan" /> public void tia

音樂網站開發:實現按鈕切換頁面背景圖的功能

        最近這一星期在做一個簡單小型的音樂播放器網站,目前各種功能基本都已經實現,包括切換上一曲下一曲,播放與暫停,隨機播放單曲迴圈順序播放模式切換,一首播放完畢自動按模式切換至下一曲,載入單句歌詞及所有歌詞等功能。另外就是本篇部落格要介紹的功能了,點

ViewPager+RadioGroup+RadioButton實現滑動切換頁面按鈕切換頁面

一:效果圖: 二:程式碼: 首先  根據我們有幾個頁面就設定幾個Fragment, 主函式: public class MainActivity extends AppCompatActivity { private ViewPager viewpager;

Struts2國際化例項(按鈕實現中英文登陸頁面的切換)

相關原理: 用不同國家的語言描述相同的資訊,並放在各自對應的.properties屬性檔案中,程式根據執行時環境決定載入哪個檔案。 整體專案結構要注意: (jar包位置不要放錯) 1.新建一個專案Struts2Demo。 2.在src下新建兩個資原始檔。

Android studio按鈕隱藏頁面後再恢復頁面

那如果想要再點選按鈕顯示佈局怎麼辦呢? 設定一個全域性變數tag,初始化=0,onclick2是按鈕的點選事件,呼叫函式,這個函式就是用來控制佈局隱藏還是顯示的,再點選後設置其隱藏還是顯示,接著修改tag的值,這樣下一次點選就會執行另一個按鈕的動作了 public

頁面按鈕實現複製功能

引入clipboard.js; htm程式碼: <p class="link-div-p1">優惠券連結:<span id="link-span">http://</span></p> <!--<span sty