android如何做带有图片的单选弹出框,如图

highwaylau 2011-10-07 10:14:34

请问要若出上图带有图片的单选弹出框,大概要怎么做,比较急,在线等
...全文
633 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
小裴同学 2011-10-08
  • 打赏
  • 举报
回复
异步加载图片的dialog。你修改下把。
/**
* Method name: dealWallPaper<BR>
* Method description:处理墙纸 <BR>
*
*/
private void dealWallPaper() {
ImageView imageView03 = (ImageView) this
.findViewById(R.id.ss_01_03_img03);
imageView03.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// show dialog
Context context = v.getContext();
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ListView listView = (ListView) mInflater.inflate(R.layout.listview, null);

// 获得所有的图片
ArrayList<PathName> list = getWallPapers();

// 初始显示5张墙纸
ArrayList<PathName> tempList = new ArrayList<PathName>();
for(int i =0;i< list.size() && i< 5;i++){
tempList.add(list.get(i));
}

// 墙纸显示的适配器
WallPaperAdapter adapter = new WallPaperAdapter(context, tempList);
listView.setAdapter(adapter);

// 异步加载墙纸
showPapers(adapter, list, scene.getWallpaper());

new AlertDialog.Builder(context).setTitle(R.string.ss0103_wallpaper_detail)

.setView(listView)
.setPositiveButton(R.string.common_ok, new WallPaperListener(adapter))
.setNegativeButton(R.string.common_cancel, new WallPaperListener(adapter))
.show();
}

});
}

/**
* Method name: getWallPapers<BR>
* Method description: 获得所有的墙纸<BR>
*
* @return
*/
private ArrayList<PathName> getWallPapers(){
String status = Environment.getExternalStorageState();
ArrayList<PathName> list=null;
list=SceneUtil.getResources(null, this, MediaStore.Images.Media.INTERNAL_CONTENT_URI,
MediaStore.Images.Media.DATA + " like ?", "%wallpaper%");
if (status.equals(Environment.MEDIA_MOUNTED)) {
list = SceneUtil.getResources(list, this,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
null,null);
// list = SceneUtil.getResources(list, this,
// MediaStore.Images.Media.INTERNAL_CONTENT_URI,
// MediaStore.Images.Media.DATA + " like ?", "/system/customize/resource/htc_wallpaper%");
// MediaStore.Images.Media.DATA + " like ?", "/system/media/hw_image/wallpaper%");
list=SceneUtil.getResources(list, this, MediaStore.Images.Media.INTERNAL_CONTENT_URI, null, null);
}
return list;
}

/**
* Method name: showPapers<BR>
* Method description: 异步加载墙纸<BR>
*
* @param adapter
* @param wallpaper
*/
private void showPapers(WallPaperAdapter adapter,ArrayList<PathName> list, String wallpaper){
ImageLoadTask task = new ImageLoadTask(list, adapter, 5);
task.execute(wallpaper);
}


package com.jftt.smart.activity.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.jftt.smart.R;
import com.jftt.smart.pojo.PathName;
import com.jftt.smart.util.SceneUtil;

public class WallPaperAdapter extends BaseAdapter {
private LayoutInflater inflater;
private ArrayList<PathName> items;
public WallPaperAdapter(Context context, ArrayList<PathName> list){
this.inflater = LayoutInflater.from(context);
items = new ArrayList<PathName>();

if(list != null){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 16;
for(PathName bean : list){
bean.image = SceneUtil.decodeBitmap(bean.path, options);
items.add(bean);
}
}
}

public void clear() {
items.clear();
notifyDataSetChanged();
}

public void add(PathName bean) {
items.add(bean);
}

public int getCount() {
// TODO Auto-generated method stub
return items.size();
}

public PathName getItem(int position) {
// TODO Auto-generated method stub
return items.get(position);
}

public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

public boolean isEnabled(int position) {
return false;
}

public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_item_001, parent, false);

holder = new ViewHolder();
holder.imageView = (ImageView) convertView.findViewById(R.id.li001_img001);
holder.textView = (TextView) convertView.findViewById(R.id.li001_tv001);
holder.radioBtn = (RadioButton) convertView.findViewById(R.id.li001_rb001);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}

PathName bean = items.get(position);
holder.imageView.setImageBitmap(bean.image);
holder.textView.setText(bean.name);
holder.radioBtn.setChecked(bean.checked);
holder.radioBtn.setOnClickListener(new SingleChoiceListener(position));
return convertView;
}

private class SingleChoiceListener implements OnClickListener {
private int position;
public SingleChoiceListener(int position) {
this.position = position;
}

public void onClick(View arg0) {
items.get(position).checked = true;
for (int i = 0; i < items.size(); i++) {
if (i != position) {
items.get(i).checked = false;
}
}
WallPaperAdapter.this.notifyDataSetChanged();
}
}
}

class ViewHolder {
public TextView textView;
public ImageView imageView;
public RadioButton radioBtn;
}
highwaylau 2011-10-08
  • 打赏
  • 举报
回复
附上图片链接http://hi.csdn.net/space-9942144-do-album-picid-938945.html
highwaylau 2011-10-08
  • 打赏
  • 举报
回复
念茜 2011-10-07
  • 打赏
  • 举报
回复
图片先上传到csdn个人空间相册,再付链接。

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧