我目前有一个简单的列表视图适配器,其中包含两行文本。我接下来要做的是添加显示用户在列表视图中拍摄的照片的选项。我修改了我的列表适配器,如下所示:
standardAdapter = new SimpleAdapter(this, list, R.layout.post_layout,
new String[] { "time", "post", "image"}, new int[] {
R.id.postTimeTextView, R.id.postTextView, R.id.post_imageView});
然后我像往常一样将它添加到哈希映射并刷新适配器:
// create a new hash map with the text from the post
feedPostMap = new HashMap<String, Object>();
feedPostMap.put("time", currentTimePost);
feedPostMap.put("post", post);
if(photoWasTaken == 1){
feedPostMap.put("image", pictureTaken);
}
//add map to list
list.add(feedPostMap);
// refresh the adapter
standardAdapter.notifyDataSetChanged();
最后,这是结果活动的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "ON activity for result- CAMERA");
if (resultCode == Activity.RESULT_OK) {
//get and decode the file
pictureTaken = BitmapFactory.decodeFile("/sdcard/livefeedrTemp.png");
//Display picture above the text box
imageViewShowPictureTaken.setImageBitmap(pictureTaken);
displayPhotoLayout.setVisibility(LinearLayout.VISIBLE);
//NEW - make photo variable = 1
photoWasTaken = 1;
}
}
但是我遇到了一个问题。位图形式的照片未添加到列表视图中。它只是显示为空白区域。我在这里做错了吗?其次,如果用户决定不拍照,则不应显示图像视图。我不确定如何实现这一点。我应该创建一个自定义列表适配器吗?
谢谢你的帮助