`

android开发过程中遇到的一些问题(包括自定义ProgressBar, Intent, Animation, ListView, RadioButton)

阅读更多

问题如下:

1.在自定义的ListView中,在一个Item中同时添加图片、文字、单选按钮时很困难。

最简单的解决办法(网上摘录):

把单选按钮用图片表示即可,然后使用SimpleAdapter放进ListView中,代码如下

  1. simpleAdapter =  new  SimpleAdapter( this , getData(),  
  2.                 R.layout.picture_info, new  String[] { imageViewIdStr,  
  3.                         pictureNameIdStr, picturePixelIdStr, radioImageIdStr },  
  4.                 new   int [] { R.id.imageViewId, R.id.pictureNameId,  
  5.                         R.id.picturePixelId, R.id.radioImageId });  
  6.   
  7.         listView.setOnItemClickListener(new  OnListClickListener());  
  8.         listView.setAdapter(simpleAdapter);  
  9. //////////////////////////////////   
  10. private   class  OnListClickListener  implements  OnItemClickListener {  
  11.   
  12.         public   void  onItemClick(AdapterView<?> arg0, View arg1,  int  arg2,  
  13.                 long  arg3) {  
  14.             // TODO Auto-generated method stub   
  15.             ChangeRadioImage(selectItemIndex, false );  
  16.             ChangeRadioImage(arg2, true );  
  17.             selectItemIndex = arg2;  
  18.         }  
  19. //主要是下面这个函数用来选中和未选中时交换图片的   
  20.                 private   void  ChangeRadioImage( int  position,  boolean  isChangeImage) {  
  21.             SimpleAdapter tmpSimpleAdapter = simpleAdapter;  
  22.             HashMap<String, Object> hm = (HashMap<String, Object>) simpleAdapter  
  23.                     .getItem(position);  
  24.   
  25.             if  (isChangeImage) {  
  26.                 hm.put("radioImageId" , R.drawable.pressed);  
  27.             } else  {  
  28.                 hm.put("radioImageId" , R.drawable.press);  
  29.             }  
  30.             tmpSimpleAdapter.notifyDataSetChanged();  
  31.         }  

2.在ListView中选中一项时,要弹出一个对话框,框中要有动画,这个困扰我很久,其实就是自定义对话框。

解决办法:

(1)使用AnimationDrawable,但是使用它时必须要以事件触发控件才能使图片活动起来,此办法不佳,代码如下

  1. AlertDialog.Builder alertBuild =  new  AlertDialog.Builder( this ); //创建对话框构造器   
  2.  AlertDialog alertDialog;  
  3.  LayoutInflater inflater = LayoutInflater.from(this );  
  4.  View layout = inflater.inflate(R.layout.anim_dialog,  
  5.  (ViewGroup) findViewById(R.id.layoutId));  
  6.  imageAnim = (ImageView) layout.findViewById(R.id.imageAnimId);  
  7.  imageAnim.setBackgroundResource(R.drawable.fly01_anim);  
  8.  Button btn = (Button) layout.findViewById(R.id.testButtonId);  
  9.  btn.setOnClickListener(new  OnClickListener() {  
  10.   
  11.  public   void  onClick(View v) {  
  12.  // TODO Auto-generated method stub   
  13.  AnimationDrawable anim = (AnimationDrawable) imageAnim  
  14.  .getBackground();  
  15.  anim.stop();  
  16.  anim.start();  
  17.  }  
  18.  });  
  19.  alertBuild.setTitle(pictureName[id]);  
  20.  alertBuild.setView(layout);  
  21.  alertDialog = alertBuild.create();  
  22.  return  alertDialog;  
  1. ///////////anim_dialog.xml  
  2. <? xml   version = "1.0"   encoding = "utf-8" ?>   
  3. < LinearLayout   
  4.   xmlns:android = "http://schemas.android.com/apk/res/android"   
  5.   android:id = "@+id/layoutId"   
  6.   android:layout_width = "fill_parent"   
  7.   android:layout_height = "fill_parent"   
  8.   android:orientation = "vertical" >   
  9.   < ImageView   
  10.     android:id = "@+id/imageAnimId"   
  11.     android:layout_width = "wrap_content"   
  12.     android:layout_height = "wrap_content"   />      
  13. < Button   
  14.     android:id = "@+id/testButtonId"   
  15.     android:layout_width = "fill_parent"   
  16.     android:layout_height = "wrap_content"   
  17.     android:text = "Test" />    
  18. </ LinearLayout >   
  19. //////////////////////fly01_anim.xml  
  20. <? xml   version = "1.0"   encoding = "utf-8" ?>   
  21. < animation-list   
  22.     xmlns:android = "http://schemas.android.com/apk/res/android"   
  23.     android:oneshot = "false" >   
  24.     < item   android:drawable = "@drawable/fly01001"   android:duration = "100"   />   
  25.     < item   android:drawable = "@drawable/fly01002"   android:duration = "100"   />   
  26.     < item   android:drawable = "@drawable/fly01003"   android:duration = "100"   />   
  27.     < item   android:drawable = "@drawable/fly01004"   android:duration = "100"   />   
  28.     
    分享到:
    评论

相关推荐

    Android典型技术模块开发详解

    第一篇 Android开发初步 第1章 Android初识 1.1 Android简介 1.1.1 认识Android 1.1.2 Android系统框架 1.1.3 应用程序框架 1.2 Eclipse开发环境 1.2.1 安装ADT插件 1.2.2 安装SDK 1.2.3 配置源代码 1.2.4 创建AVD ...

    Android基础知识详解

    Android应用开发和Dalvik虚拟机 15 Activity生命周期 16 一、Activity栈 16 二、Activity的4种状态 16 三、Activity的生命周期 17 四、实例说明 18 Android控件的继承关系 22 一、View与ViewGroup关系 22 二、各控件...

    疯狂Android讲义源码

     2.1.5 开发自定义View 43  2.2 布局管理器 46  2.2.1 线性布局 47  2.2.2 表格布局 49  2.2.3 帧布局 52  2.2.4 相对布局 55  2.2.5 绝对布局 58  2.3 基本界面组件 60  2.3.1 文本框(TextView)与编辑框...

    疯狂Android讲义.part2

    2.1.5 开发自定义View 43 2.2 布局管理器 46 2.2.1 线性布局 47 2.2.2 表格布局 49 2.2.3 帧布局 52 2.2.4 相对布局 55 2.2.5 绝对布局 58 2.3 基本界面组件 60 2.3.1 文本框(TextView)与编辑框 (EditText)的...

    疯狂Android讲义.part1

    2.1.5 开发自定义View 43 2.2 布局管理器 46 2.2.1 线性布局 47 2.2.2 表格布局 49 2.2.3 帧布局 52 2.2.4 相对布局 55 2.2.5 绝对布局 58 2.3 基本界面组件 60 2.3.1 文本框(TextView)与编辑框 (EditText)的...

    疯狂Android讲义(第2版)源代码 第6章~第9章

    《疯狂Android讲义(第2版)》.(李刚).源代码 疯狂Android讲义目录结构: 第2章、Android应用程序界面设计,即View 2.2、布局管理(Layout):LinearLayout、TableLayout、FrameLayout、RelativeLayout; 2.3、基本...

    Android实例代码

    第3章、Android事件处理,包括按键响应机制和消息传递机制 3.2、基于监听器的事件处理: 3.3、基于回调的事件的处理: 3.4、响应系统设置的事件: 3.5、Handler消息传递机制: 第4章、深入理解Activity 4.1、...

    ophone&android 开发完全讲义随书源码

    ├─ch02 │ └─ch02_showdatetime │ ├─assets │ ├─bin │ │ └─net │ │ └─blogjava │ │ └─mobile │ ├─gen │ │ └─net │ │ └─blogjava │ │ └─mobile ...│ │ └─src...

Global site tag (gtag.js) - Google Analytics