如何为Listview添加两种不同的布局?

时间:2015-06-19 12:13:57

标签: android listview android-imageview android-image

我想开发类似WhatsApp聊天的界面。

我使用ListView实现了整个界面。我可以将文字添加到ListView。但我不知道如何将图像添加到与附件相同的ListView

我的主要目标是将文字,图片,音频文件和视频文件添加到单ListView

请帮帮我。

2 个答案:

答案 0 :(得分:1)

最后我得到了答案。

这是我在ListView中组合TextView和ImageView的代码:
adding-more-than-two-different-layouts-to-listview.html

答案 1 :(得分:0)

因此,如果能够很好地理解问题,您可以从SD卡或图库中加载图像并加载到listview项目的imageview中,对吧?

从文件加载图片:

.controller('newsController', function($scope, newsService) {
    newsService.getnews().then(
      function(newsData) {
        $scope.newsData = newsData
      }, 
      function optionalErrorhandler() {});
})

或者如果您想从图库中选择:

File imgFile = new  File("/sdcard/Images/test_image.jpg");

if(imgFile.exists()){

Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);

myImage.setImageBitmap(myBitmap);

}

您可以从listview onItemClick侦听器调用这些方法,并在完成图像加载后返回Bitmap。

相关问题