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.     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值