Android中使用隐式Intent完成“猜数游戏”的代码清单_第1页
Android中使用隐式Intent完成“猜数游戏”的代码清单_第2页
Android中使用隐式Intent完成“猜数游戏”的代码清单_第3页
Android中使用隐式Intent完成“猜数游戏”的代码清单_第4页
Android中使用隐式Intent完成“猜数游戏”的代码清单_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Android中使用隐式Intent完成“猜数游戏”的代码清单范美英(北京信息职业技术学院)摘 要:Android中可以使用Intent完成界面切换、组件之间的通信等功能,本文详细罗列了使用隐式Intent完成“猜数游戏”的代码清单。关键词: Android;Intent;猜数游戏;代码清单 1 src/MainActivity.java类的代码public class MainActivity extends Activity Intent i;final String key="num_key" Overrideprotected void onCreate(Bundl

2、e savedInstanceState) super.onCreate(savedInstanceState);i=this.getIntent();public void clickIMGs(View v)switch(v.getId()i.putExtra(key, 1);break;i.putExtra(key, 2);break;i.putExtra(key, 3);break;i.putExtra(key, 4);break;i.putExtra(key, 5);break;i.putExtra(key, 6);break;i.putExtra(key, 7);break;i.pu

3、tExtra(key, 8);break;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) /屏蔽android手机中的back键return false;return super.onKeyDown(keyCode, eve

4、nt);2 src/ BackActivity.java类的代码public class BackActivity extends Activity Handler h;int secs=5;final int REQUEST_CODE=1;TextView tv;Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);h=new Handler()Overridepublic void handleMessage(Message msg) this.obtain

5、Message();switch(msg.what)case 0:tv.setText("选图剩余时间:"+secs);if(secs=1)gotoMain();break;default:break;private void gotoMain() /隐式跳转/在AndroidManifest.xml中进行了相关配置Intent i=new Intent();startActivityForResult(i, REQUEST_CODE);Thread wt= new MyThread();wt.start();public class MyThread extends Th

6、read 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();Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) if(requestCo

7、de=REQUEST_CODE && resultCode=RESULT_OK)tv.setText("您刚才选择了数字值为"+data.getIntExtra("num_key", 0)+"的图片");super.onActivityResult(requestCode, resultCode, data);3 res/layout/activity_main.xml的代码清单 android:layout_width="fill_parent" android:layout_height=&qu

8、ot;fill_parent" android:layout_gravity="center" android:background="#fff"> <TableRow android:id="+id/tableRow1" android:layout_width="match_parent" android:layout_height="wrap_content" > <ImageView android:id="+id/img_1" an

9、droid:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:src="drawable/one" /> <ImageView android:id="+id/img_2" android:layout_width="0dp" android:layout_height=&q

10、uot;140dp" android:layout_weight="1" android:onClick="clickIMGs" android:src="drawable/two" /> <ImageView android:id="+id/img_3" android:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android

11、:onClick="clickIMGs" android:src="drawable/three" /> </TableRow> <TableRow android:id="+id/tableRow2" android:layout_width="match_parent" android:layout_height="wrap_content" > <ImageView android:id="+id/img_4" android:lay

12、out_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:src="drawable/four" /> <ImageView android:id="+id/img_5" android:layout_width="0dp" android:layout_height="140d

13、p" android:layout_weight="1" android:onClick="clickIMGs" android:scaleType="centerCrop" android:src="drawable/five" /> <ImageView android:id="+id/img_6" android:layout_width="0dp" android:layout_height="140dp" android:l

14、ayout_weight="1" android:onClick="clickIMGs" android:src="drawable/six" /> </TableRow> <TableRow android:id="+id/tableRow3" android:layout_width="match_parent" android:layout_height="wrap_content" > <ImageView android:id=&

15、quot;+id/img_7" android:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:scaleType="centerCrop" android:src="drawable/seven" /> <ImageView android:id="+id/img_8&q

16、uot; android:layout_width="0dp" android:layout_height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:src="drawable/eight" /> <ImageView android:id="+id/img_9" android:layout_width="0dp" android:layout_

17、height="140dp" android:layout_weight="1" android:onClick="clickIMGs" android:scaleType="centerCrop" android:src="drawable/nine" /> </TableRow></TableLayout>4 res/layout/activity_back.xml的代码清单<?xml version="1.0" encoding=&q

18、uot;utf-8"?> android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="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.xml的配置清单<?xml version="1.0" encoding="utf-8"?> androi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论