zoukankan      html  css  js  c++  java
  • 自定义dialog包含一个显示图片的listview

    package com.brandroidapp.ui;
    
    
    import java.util.ArrayList;
    
    import com.brandroidapp.activity.R;
    import com.brandroidapp.adapter.ImageListViewAdapter;
    
    import android.app.Dialog;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.widget.ListView;
    
    public class ImageDialog extends Dialog  implements android.view.View.OnClickListener{
    	private static ImageDialog imageDialog=null;
    	private static LayoutInflater layoutInflater;
    	private Context  context;
    	public ImageDialog(Context context) {
    		super(context);
    		this.context =  context;
    		layoutInflater = LayoutInflater.from(context);
    	}
    
    	public static ImageDialog  Create(Context context) {
    		
    		imageDialog  =  new ImageDialog(context);
    		imageDialog.setContentView(layoutInflater.inflate(R.layout.onlinedialog, null));
    		ListView  listView   =  (ListView) imageDialog.findViewById(R.id.listView1);
    		ArrayList<Integer>  imageList =  new ArrayList<Integer>();
    		imageList.add(R.drawable.gongshang);
    		imageList.add(R.drawable.nongye);
    		ImageListViewAdapter  imageListViewAdapter  =  new ImageListViewAdapter(context, imageList, layoutInflater);
    		listView.setAdapter(imageListViewAdapter);
    		return  imageDialog;
    	}
    	
    	@Override
    	public void onClick(View v) {
    		// TODO Auto-generated method stub
    		
    	}
    
    }
    
    
    
    
    
    package com.brandroidapp.adapter;
    
    import java.util.List;
    
    import com.brandroidapp.activity.R;
    import com.brandroidapp.adapter.RefreshListViewAdapter.ListItemView;
    import com.brandroidapp.bean.StockBean;
    
    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    public class ImageListViewAdapter  extends  BaseAdapter {
    	private Context context;// 运行上下文
    	private List<Integer> listItems;// 数据集合
    	private LayoutInflater listContainer;// 视图容器
    	static class ListItemView { // 自定义控件集合
    		public ImageView imageView;
    		
    		
    	}
    	public ImageListViewAdapter(Context context, List<Integer> listItems,
    			LayoutInflater listContainer) {
    		super();
    		this.context = context;
    		this.listItems = listItems;
    		this.listContainer = listContainer;
    	}
    
    	@Override
    	public int getCount() {
    		// TODO Auto-generated method stub
    		return listItems.size();
    	}
    
    	@Override
    	public Object getItem(int position) {
    		// TODO Auto-generated method stub
    		return position;
    	}
    
    	@Override
    	public long getItemId(int position) {
    		// TODO Auto-generated method stub
    		return position;
    	}
    
    	@Override
    	public View getView(int position, View convertView, ViewGroup parent) {
    
    
    		// 自定义视图
    		ListItemView listItemView = null;
    		
    		if (convertView == null) {
    			// 获取list_item布局文件的视图
    				convertView = listContainer.inflate(R.layout.imagelistviewitem, null);
    				
    			listItemView = new ListItemView();
    			// 获取控件对象
    			listItemView.imageView  = (ImageView) convertView.findViewById(R.id.imageView1);
    			// 设置控件集到convertView
    			convertView.setTag(listItemView);
    		} else {
    			listItemView = (ListItemView) convertView.getTag();
    		}
    		
    		listItemView.imageView.setImageResource(listItems.get(position));
    		
    		return convertView;
    	}
    
    }
    
    
    
    
    ImageDialog imageDialog  =  ImageDialog.Create(OnLineActivity.this);
    		imageDialog.show();//调用代码


     

  • 相关阅读:
    Codeforces Round #631 (Div. 1) B. Dreamoon Likes Sequences 题解(思维+求贡献)
    牛客练习赛66 C公因子 题解(区间gcd)
    evincevim控喜欢的pdf阅读器
    水手郑智化
    使用diskpart管理自己的分区
    Hacker's Browser
    How Browser Works
    解决vim ctags R失败的问题
    ubuntu更改登录对话框
    使用bcdedit删除多个Windows系统
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3093817.html
Copyright © 2011-2022 走看看