你可以在图像中检查我在listview左侧imageview中有2个视图和右侧buttonview其他是textview但是当imageview调用启动另一个活动时我必须调用不同的活动,如果是点击按钮而不是被称为不同的活动那么如何才能在listview中获得特定的按钮或图像clicke事件
Activity Class.java
liststipciations.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,
long l) {
Log.e("list stipcitaions", "-->"+liststipciations.getItemIdAtPosition(position));
}
});
Adapter Class.java
public class LazyAdapterStipciationsAdvertise extends BaseAdapter implements OnClickListener{
private static final String TAG_SHOWTEXT="showtext";
String showtext;
private static final String TAG_PRODUCTINFO="product_info";
String productinfo;
private static final String TAG_THUMBIMAGE="thumbsrc";
String thumbimage;
private static final String TAG_STIPCIATED="stipciated";
String stipciated;
private static final String TAG_DISTANCE="distance";
private Activity activity;
private ArrayList<HashMap<String, String>> result;
private static LayoutInflater inflater=null;
public GridImageLoader gridimageLoader;
int imageWidth;
int imageheight;
Context context;
int width;
int height;
int layoutwidth;
int layoutheight;
public LazyAdapterStipciationsAdvertise(Activity a, ArrayList<HashMap<String, String>> r)
{
activity = a;
result=r;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
gridimageLoader=new GridImageLoader(activity.getApplicationContext());
width = a.getWindowManager().getDefaultDisplay().getWidth();
height=a.getWindowManager().getDefaultDisplay().getHeight();
imageWidth = ((width*18)/100);
layoutheight=((height*20)/100);
}
public int getCount() {
return result.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder
{
public TextView textpromotional;
public TextView textdistance;
public ImageView imageadvertise;
public ImageView imagestipciate;
public ImageView imagestipciated;
}
public View getView(int position, View convertView, ViewGroup parent)
{
View vi=convertView;
ViewHolder holder;
if(convertView==null)
{
vi = inflater.inflate(R.layout.stipciationslist, null);
holder=new ViewHolder();
holder.textpromotional=(TextView)vi.findViewById(R.id.textpromotional);
holder.textdistance=(TextView)vi.findViewById(R.id.textdistance);
holder.imageadvertise=(ImageView)vi.findViewById(R.id.imageadvertise);
holder.imageadvertise.setLayoutParams(new LinearLayout.LayoutParams(imageWidth,imageWidth));
holder.imagestipciate=(ImageView)vi.findViewById(R.id.imagestipciate);
holder.imagestipciated=(ImageView)vi.findViewById(R.id.imagestipciated);
vi.setTag(holder);
}
else
holder=(ViewHolder)vi.getTag();
holder.textpromotional.setText(result.get(position).get(TAG_SHOWTEXT));
holder.textdistance.setText(result.get(position).get(TAG_DISTANCE));
holder.imageadvertise.setTag(result.get(position).get(TAG_THUMBIMAGE));
holder.imageadvertise.setId(1);
if(result.get(position).get(TAG_STIPCIATED).equals("1"))
{
holder.imagestipciated.setVisibility(View.VISIBLE);
holder.imagestipciated.setId(2);
holder.imagestipciate.setVisibility(View.INVISIBLE);
}
if(result.get(position).get(TAG_STIPCIATED).equals("0"))
{
holder.imagestipciate.setVisibility(View.VISIBLE);
holder.imagestipciate.setId(3);
holder.imagestipciated.setVisibility(View.INVISIBLE);
}
gridimageLoader.DisplayImage(result.get(position).get(TAG_THUMBIMAGE), activity, holder.imageadvertise);
return vi;
}
public static float convertDpToPixel(float dp, Context context){
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float px = dp * (metrics.densityDpi/160f);
return px;
}
}
答案 0 :(得分:2)
您可以在setOnClickListener
方法中为按钮和图像实现getView
。希望下面的代码可以帮助你。
Button myButton
public View getView(int position, View convertView, ViewGroup parent)
{
myButton = (Button)convertView.findViewById(R.id.myButton);
myButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(CurrentActivity.this, OtherActivity.class);
startActivity(intent);
}
});
}