Android中使用隱式Intent完成“猜數(shù)游戲”的代碼清單_第1頁
Android中使用隱式Intent完成“猜數(shù)游戲”的代碼清單_第2頁
Android中使用隱式Intent完成“猜數(shù)游戲”的代碼清單_第3頁
Android中使用隱式Intent完成“猜數(shù)游戲”的代碼清單_第4頁
Android中使用隱式Intent完成“猜數(shù)游戲”的代碼清單_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、Android中使用隱式Intent完成“猜數(shù)游戲”的代碼清單范美英(北京信息職業(yè)技術(shù)學院)摘 要:Android中可以使用Intent完成界面切換、組件之間的通信等功能,本文詳細羅列了使用隱式Intent完成“猜數(shù)游戲”的代碼清單。關(guān)鍵詞: Android;Intent;猜數(shù)游戲;代碼清單 1 src/MainActivity.java類的代碼package com.zyk.getvaluesfromactivity;import android.app.Activity;import android.content.Intent;import android.os.Bundle;impor

2、t android.view.KeyEvent;import android.view.View;public class MainActivity extends Activity Intent i;final String key="num_key" Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);i=this.getIntent();public voi

3、d clickIMGs(View v)switch(v.getId()case R.id.img_1:i.putExtra(key, 1);break;case R.id.img_2:i.putExtra(key, 2);break;case R.id.img_3:i.putExtra(key, 3);break;case R.id.img_4:i.putExtra(key, 4);break;case R.id.img_5:i.putExtra(key, 5);break;case R.id.img_6:i.putExtra(key, 6);break;case R.id.img_7:i.p

4、utExtra(key, 7);break;case R.id.img_8:i.putExtra(key, 8);break;case R.id.img_9:i.putExtra(key, 9);break;default:break;goBack();private void goBack() this.setResult(RESULT_OK, i);this.finish();Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) if (keyCode = KeyEvent.KEYCODE_BACK) /屏蔽androi

5、d手機中的back鍵return false;return super.onKeyDown(keyCode, event);2 src/ BackActivity.java類的代碼package com.zyk.getvaluesfromactivity;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.widget.TextView;public

6、 class BackActivity extends Activity Handler h;int secs=5;final int REQUEST_CODE=1;TextView tv;Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);this.setContentView(R.layout.activity_back);tv=(TextView) this.findViewById(R.id.tv_show);h=new Handler()Overri

7、depublic void handleMessage(Message msg) this.obtainMessage();switch(msg.what)case 0:tv.setText("選圖剩余時間:"+secs);if(secs=1)gotoMain();break;default:break;private void gotoMain() /隱式跳轉(zhuǎn)/在AndroidManifest.xml中進行了相關(guān)配置Intent i=new Intent();i.setAction("com.zyk.main");startActivityForRes

8、ult(i, REQUEST_CODE);Thread wt= new MyThread();wt.start();public class MyThread extends Thread Overridepublic void run() super.run();while(secs>=1)try Message m=new Message();m.obj=secs;m.what=0;h.sendMessage(m);Thread.sleep(1000);secs-; catch (InterruptedException e) e.printStackTrace();Override

9、protected void onActivityResult(int requestCode, int resultCode, Intent data) if(requestCode=REQUEST_CODE && resultCode=RESULT_OK)tv.setText("您剛才選擇了數(shù)字值為"+data.getIntExtra("num_key", 0)+"的圖片");super.onActivityResult(requestCode, resultCode, data);3 res/layout/act

10、ivity_main.xml的代碼清單<TableLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:background="#fff"> <TableRow android:id="+id/tableRow1" android:layout_width=

11、"match_parent" android:layout_height="wrap_content" > <ImageView android:id="+id/img_1" android:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:src="drawabl

12、e/one" /> <ImageView android:id="+id/img_2" android:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:src="drawable/two" /> <ImageView android:id="+id/img_3&

13、quot; android:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:src="drawable/three" /> </TableRow> <TableRow android:id="+id/tableRow2" android:layout_width="mat

14、ch_parent" android:layout_height="wrap_content" > <ImageView android:id="+id/img_4" android:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:src="drawable/four&qu

15、ot; /> <ImageView android:id="+id/img_5" android:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:scaleType="centerCrop" android:src="drawable/five" /> <Ima

16、geView android:id="+id/img_6" android:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:src="drawable/six" /> </TableRow> <TableRow android:id="+id/tableRow3"

17、; android:layout_width="match_parent" android:layout_height="wrap_content" > <ImageView android:id="+id/img_7" android:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" an

18、droid:scaleType="centerCrop" android:src="drawable/seven" /> <ImageView android:id="+id/img_8" android:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:src="

19、drawable/eight" /> <ImageView android:id="+id/img_9" android:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:scaleType="centerCrop" android:src="drawable/nine&qu

20、ot; /> </TableRow></TableLayout>4 res/layout/activity_back.xml的代碼清單<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation=&quo

21、t;vertical" > <TextView android:id="+id/tv_show" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /></FrameLayout>5 AndroidManifest

22、.xml的配置清單<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android=" package="com.zyk.getvaluesfromactivity" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="drawable/ic_launcher" android:label="string/app_name"

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論