listView 与 按钮共存

package com.uumap.adapter;

import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.uumap.Entity.PoiInfo;
import com.uumap.MapInterface.FavoriteActivity;
import com.uumap.MapInterface.FindActivity;
import com.uumap.MapInterface.R;
import com.uumap.MapInterface.mapIndex;
import com.uumap.adapter.FavoriteListAdapter.lvButtonListener;
import com.uumap.mapview.Map;
import com.uumap.util.CacheTools;
import com.uumap.util.FileUtil;
import com.uumap.util.StrUtil;
import com.uumap.views.PoiImgView;

public class FindResutlAdapter extends BaseAdapter
{

private List<PoiInfo> itemList;
private Context context;
private LayoutInflater lif;
private ViewHolder holder;

public FindResutlAdapter(Context context, List<PoiInfo> itemList)
{
this.context = context;
this.itemList = itemList;
lif = LayoutInflater.from(context);
}

final class ViewHolder
{
public Button mapBtn;
public TextView tv1;
public TextView tv2;
}

@Override
public int getCount()
{
return itemList.size();
}

@Override
public Object getItem(int position)
{
return itemList.get(position);
}

@Override
public long getItemId(int position)
{
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{

if (convertView == null)
{
holder = new ViewHolder();
convertView = lif.inflate(R.layout.findresult_item, null);
holder.mapBtn=(Button) convertView.findViewById(R.id.mapBtn);
holder.tv1 = (TextView) convertView.findViewById(R.id.poi_name);
holder.tv2 = (TextView) convertView.findViewById(R.id.poi_address);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}


holder.tv1.setText(itemList.get(position).getName());

String address = "";
address = itemList.get(position).getAddress();
if (address!=null){
if ("".equals(address.trim()))
{
address = "暂无地址信息";
}
}else{
address = "暂无地址信息";
}

holder.tv2.setText(address);

// holder.mapBtn.setOnClickListener(new lvButtonListener(position));

return convertView;
}
public void getMapPoint(int position) {
mapIndex.jwxy[0] = itemList.get(position).getJwx();
mapIndex.jwxy[1] = itemList.get(position).getJwy();
String title = itemList.get(position).getName();
// Map.locateJwxy[0] = mapIndex.jwxy[0];
// Map.locateJwxy[1] = mapIndex.jwxy[1];
CacheTools.select = "SelectPoiActivity";
Bitmap poiImg = BitmapFactory.decodeResource(Map.curContext.getResources(),
R.drawable.poi);
PoiImgView iv = new PoiImgView(Map.curContext, 0);
iv.setImageBitmap(poiImg);

PoiInfo poi = new PoiInfo();
poi.setIv(iv);
poi.setJwx(mapIndex.jwxy[0]);
poi.setJwy(mapIndex.jwxy[1]);
poi.setName(title);
poi.setResultId(0);
poi.setSelect(false);
Map.tmDiv.rstPoi = poi;

if(Map.poiInfos!=null){
Message message = Message.obtain();
mapIndex.selectPoi.handleMessage(message);
}

}
class lvButtonListener implements OnClickListener {
private int position;

lvButtonListener(int pos) {
position = pos;
}
public void onClick(View v) {
int vid = v.getId();

if (vid == holder.mapBtn.getId()) {
getMapPoint(position);
((FindActivity) context).finish();
}
}
}


}

你可能感兴趣的:(LIStveiw)