Android开发实现列表视图和适配器配合显示图片和文字列表功能示例

  

本文实例讲述了Android开发实现列表视图和适配器配合显示图片和文字列表功能。分享给大家供大家参考,具体如下:

  

<>强实际效果:

  

 Android开发实现列表视图和适配器配合显示图片和文字列表功能示例

  

<强>布局文件:

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android "   xmlns:应用=" http://schemas.android.com/apk/res-auto "   xmlns:工具=" http://schemas.android.com/tools "   android: layout_width=" match_parent "   android: layout_height=" match_parent "   工具:上下文=" .MainActivity "   面向android:=按怪薄北?   & lt; !——使用红色得分割条——比;   & lt;列表视图   android: id=癅 + id/list1”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android:分频器=" # f00”   android: dividerHeight=" 2 px "   android: headerDividersEnabled=" false "比;   & lt;/ListView>   & lt; !——用于存放和发送新的信息——比;   LinearLayout & lt;   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: layout_alignParentBottom=" true "   android: layout_marginBottom=" 0 dp”   android:背景=" # 66 ffffff "   面向android:=按怪薄北?   LinearLayout & lt;   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   面向android:=按怪薄北?   & lt; !——设置最大行数——比;   EditText & lt;   android: id=癅 + id/ifo_edit”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android:提示="请输入内容”   android: maxLines=" 6 "   android: textColorHint=" # c0c0c0 "/比;   & lt; !——存放新的图片——比;   & lt; ImageView   android: id=癅 + id/ifo_image”   android: layout_width=" 130 dp”   android: layout_height=" 110 dp”   android: src=" https://www.yisu.com/zixun/@drawable addphoto "/比;   & lt;/LinearLayout>   & lt;使用   android: layout_width=" wrap_content "   android: layout_height=皐rap_content”比;   & lt; !——点击取消发送消息——比;   & lt;按钮   android: id=癅 + id/删除”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_alignParentLeft=" true "   android: layout_gravity=白蟆?   android:文本="取消”   android: textSize=" 16 sp "/比;   & lt; !——点击发送消息——比;   & lt;按钮   android: id=癅 + id/发送”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_alignParentRight=" true "   android:文本="发送”   android: textSize=" 16 sp "/比;   & lt;/RelativeLayout>   & lt;/LinearLayout>   & lt;/RelativeLayout>      之前      

<强>代码实现部分:

        公开课MainActivity延伸AppCompatActivity {//表列表   私人List,informationsList01=new ArrayList<的在();//当前消息列表   ListView list01;//消息发送栏   EditText editText01;//存放图片   ImageView imageView01;//消息发送按钮   按钮button01_send;//记录数组长度   int arr_num=0;//定义一个数组   String [] arr1=新的字符串(arr_num);//从相册获得图片   位图的位图;//判断返回到的活动   私有静态最终int IMAGE_REQUEST_CODE=0;//图片路径   私人字符串路径;   私人处理程序处理程序=new处理程序(){   @Override   公共空间handleMessage(消息味精){   如果((整数)msg.obj==0) {   imageView01.setImageBitmap(位图);   }   super.handleMessage(味精);   }   };   @Override   保护voidcom.android.providers.downloads.documents”.equals (uri.getAuthority ())) {   Uri contentUri=ContentUris.withAppendedId (Uri.parse(“内容://下载/public_downloads”), Long.valueOf (docId));   imagePath=getImagePath (contentUri, null);   }   }else if(“内容”.equalsIgnoreCase (uri.getScheme ())) {//如果是普通类型用普通方法处理   imagePath=getImagePath (uri, null);   }else if(“文件”.equalsIgnoreCase (uri.getScheme ())) {//如果文件类型位uri直街获取图片路径即可   imagePath=uri.getPath ();   }   displayImage (imagePath);   }   私人空间handleImageBeforeKitKat(意图数据){   Uri Uri=data.getData ();   字符串imagePath=getImagePath (uri, null);   displayImage (imagePath);   }   私人字符串getImagePath (Uri Uri,字符串的选择){   字符串路径=零;//通过Uri和选择来获取真实图片路径   鼠标光标=getContentResolver ()。查询(uri, null,选择、空、空);   如果(光标!=null) {   如果(cursor.moveToFirst ()) {   路径=cursor.getString (cursor.getColumnIndex (MediaStore.Images.Media.DATA));   }   cursor.close ();   }   返回路径;   }   私人空间displayImage(字符串imagePath) {   如果(imagePath !=null) {   位图的位图=BitmapFactory.decodeFile (imagePath);   imageView01.setImageBitmap(位图);   其他}{   Toast.makeText (MainActivity。“没有得到图像”,Toast.LENGTH_SHORT),告诉();   }   }   }      

Android开发实现列表视图和适配器配合显示图片和文字列表功能示例