我为listview定制了一个适配器,它的词很好。但是,当我将 onclicklistener 设置为自定义适配器行视图中的视图时,onitemclicklistner 不起作用。
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
try{
if(convertView==null)
{
convertView=mInflater.inflate(R.layout.marker_row_view, null);
holder=new ViewHolder();
holder.Name=(TextView)convertView.findViewById(R.id.ProeprtyName);
holder.image=(ImageView)convertView.findViewById(R.id.RightArrow);
convertView.setTag(holder);
}
else
{
holder=(ViewHolder)convertView.getTag();
}
holder.Name.setText(propertyNames[position]);
if(selectedPosition == position){
Log.d("", "selected");
convertView.setBackgroundColor(Color.BLUE);
convertView.setBackgroundColor(Color.parseColor("#3B79FF"));
holder.Name.setTextColor(Color.WHITE);
}else{
//convertView.setBackgroundResource(R.drawable.savsearch_bg_district);
holder.Name.setTextColor(Color.BLACK);
}
holder.Name.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.d("fdsf", "on");
Globalclass global = (Globalclass) ((Activity)context).getApplication();
global.setMarkerTextClick(true);
}
});
holder.image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.d("fdsf", "on");
Globalclass global = (Globalclass) ((Activity)context).getApplication();
global.setMarkerTextClick(false);
}
});
}catch (Exception e) {
e.printStackTrace();
}
return convertView;
}
listview onitemclicklisner 的代码是
final MarkerInfoAdapter adapter = new MarkerInfoAdapter(PropertyMapList.this, names);
final ListView list = (ListView) CustomMarker.findViewById(R.id.listView1);
list.setAdapter(adapter);list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(
AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Log.d("", "fsdfdsfds");
((MarkerInfoAdapter)adapter).setSelected(arg2);
}
});