安卓开发实验报告.docx
《安卓开发实验报告.docx》由会员分享,可在线阅读,更多相关《安卓开发实验报告.docx(13页珍藏版)》请在冰豆网上搜索。
安卓开发实验报告
目录
一、页面跳转
二、长按图标抖动以及显示删除
一、页面跳转
功能:
通过点击button实现2个activity之间的跳转。
1.设置监听器监听点击button
2.使用intent传输数据
完整代码
1.ui_test.java
publicclassUI_TestextendsActivity{
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.incident_activity_1);
Buttonbt=(Button)findViewById(R.id.login);
bt.setOnClickListener(newOnClickListener());
}
classOnClickListenerimplementsView.OnClickListener{
publicvoidonClick(Viewv){
EditTextname=(EditText)findViewById(R.id.name);
EditTextpassword=(EditText)findViewById(R.id.password);
Bundledata=newBundle();
data.putString("name",name.getText().toString());
data.putString("password",password.getText().toString());
Intentintent=newIntent(UI_Test.this,UI_Result.class);
intent.putExtras(data);
startActivity(intent);
}
}
2.ui_result.java
publicclassUI_ResultextendsActivity{
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.incident_activity_2);
TextViewname=(TextView)findViewById(R.id.nameShow);
TextViewpassword=(TextView)findViewById(R.id.passwordShow);
Intentintent=getIntent();
Bundleresult=intent.getExtras();
name.setText("您的用户名为:
"+result.getString("name"));
password.setText("您的密码为:
"+result.getString("password"));
}
}
3.activity_1.xml
xmlversion="1.0"encoding="utf-8"?
>
android="
android:
layout_width="fill_parent"
android:
layout_height="fill_parent"
>
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
text="请输入您的信息"
android:
textSize="20sp"
/>
android:
id="@+id/tableRow1"
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
>
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
text="用户名"
android:
textSize="16sp"
/>
android:
id="@+id/name"
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
hint="请填写登录用户名"
android:
selectAllOnFocus="true">
android:
id="@+id/tableRow2"
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
>
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
text="请输入密码"
android:
textSize="16sp"
/>
android:
id="@+id/password"
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
password="true"
android:
selectAllOnFocus="true">
android:
id="@+id/tableRow3"
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
>
4.activity_2.xml
xmlversion="1.0"encoding="utf-8"?
>
android="
android:
layout_width="match_parent"
android:
layout_height="match_parent"
android:
orientation="vertical">
android:
id="@+id/nameShow"
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
textSize="18sp"
/>
android:
id="@+id/passwordShow"
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
textSize="18sp"
/>
二、长按图标抖动以及显示删除
功能:
将app列举在界面上,并且长按图标使图标进行抖动以及显示删除图标。
1.初始化一个gridview的适配器
2.通过不停转动图标实现图标的抖动以及添加删除图标
3.添加监听器实现长按图标使图标抖动及显示删除
完整代码
1.main_activity.java
publicclassMainActivityextendsActivity{
privatePackageManagermPackageManager;
privateGridViewmAppGrid;
privateListmAppList;
privateDrawablemColorDrawable;
privateGridViewAdaptermAdapter=null;
privatestaticintmAppState=0;
privatestaticfinalintAPP_DELFINISHED=0x1;
publicMainActivity(){
//TODOAuto-generatedconstructor