private CAdapterHousePostChooseType houseChooseTypeAdapter;
houseChooseTypeAdapter = new CAdapterHousePostChooseType(getApplicationContext());
p_lvHouseChooseTypeInfo.setAdapter(houseChooseTypeAdapter);
p_lvHouseChooseTypeInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
p_mCurrentPos = position;
houseChooseTypeAdapter.setCurrectPos(p_mCurrentPos);
houseChooseTypeAdapter.notifyDataSetChanged();
}
});
/* --------------------------------------------------------- */
package company.com.guoguozhuangxiu;
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;
/**
* Created by Administrator on 17-5-9.
*/
public class CAdapterHousePostChooseType extends BaseAdapter {
private Context context;
private LayoutInflater inflter;
private int p_mCurrentPos = 0;
public void setCurrectPos(int currectPos) {
this.p_mCurrentPos = currectPos;
}
public int getCurrectPos(){
return p_mCurrentPos;
}
public CAdapterHousePostChooseType(Context context) {
super();
this.context = context;
inflter = (LayoutInflater.from(context));
}
@Override
public int getCount() {
return CDataObjectHouse.g_arrStrHouseChooseTypeInfoForAdapter.length;
}
@Override
public Object getItem(int position) {
return CDataObjectHouse.g_arrStrHouseChooseTypeInfoForAdapter[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = inflter.inflate(R.layout.custom_house_choose_type_lv, null);
TextView p_tvHouseChooseType = (TextView) convertView.findViewById(R.id.tvHouseChooseType);
ImageView p_imgviewHouseChooseType = (ImageView) convertView.findViewById(R.id.imgviewHouseChooseType);
if(p_mCurrentPos == position) {
p_imgviewHouseChooseType.setImageResource(R.mipmap.ic_yes);
} else {
p_imgviewHouseChooseType.setImageResource(R.mipmap.ic_null);
}
p_tvHouseChooseType.setText(CDataObjectHouse.g_arrStrHouseChooseTypeInfoForAdapter[position]);
return convertView;
}
}