我想隐藏图像ListView
,这里我使用了自定义列表视图,BaseAdapter
请参见下图,单击Edit btn
图像 1时应该可见,
ListView 图片如下
我已经从Activity
点击完成了这段代码button
++btnClick;
if (btnClick % 2 == 0)
{
textView.setText("Edit");
baseAdapter.holder.imgPhoto.setVisibility(View.INVISIBLE);
} else {
textView.setText("Done");
Log.e("call", "Done");
baseAdapter.holder.imgPhoto.setVisibility(View.VISIBLE);
};
baseAdapter
对象在哪里BaseAdapter
,点击按钮时会发生什么,只有最后一个按钮不可见,因为它正在获得最后一个引用,我不想BaseAdapter
再次重新加载。
BaseAdapterFavotites.java
public class BaseAdapterFavotites extends BaseAdapter {
private ArrayList<SearchResults> searchArrayList;
public ArrayList<String> getSchoolId, getSchoolName;
private LayoutInflater mInflater;
public ViewHolder holder;
Context context;
public String s;
HashMap<String, String> mapSchoolToLink = new HashMap<String, String>();;
public BaseAdapterFavotites(Context context,
ArrayList<SearchResults> results, ArrayList<String> arrayId,
ArrayList<String> arraySchoolName) {
searchArrayList = results;
mInflater = LayoutInflater.from(context);
getSchoolId = arrayId;
this.context = context;
getSchoolName = arraySchoolName;
}
public int getCount() {
return searchArrayList.size();
}
public Object getItem(int position) {
return searchArrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_row_for_favorites,
null);
holder = new ViewHolder();
holder.txtSchoolNameList = (TextView) convertView
.findViewById(R.id.schoolNameFav);
holder.imgPhoto = (ImageView) convertView.findViewById(R.id.delete);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtSchoolNameList.setText(searchArrayList.get(position)
.getschoolNameFromList());
Log.e("holder", searchArrayList.get(position).getschoolNameFromList());
holder.imgPhoto.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
mapSchoolToLink.clear();
searchArrayList.remove(position);
getSchoolId.remove(position);
getSchoolName.remove(position);
notifyDataSetChanged();
Log.e("inside base", searchArrayList.toString());
Log.e("inside getSchoolId", getSchoolId.toString());
for (int i = 0; i < getSchoolId.size(); i++) {
mapSchoolToLink.put(getSchoolName.get(i),
getSchoolId.get(i));
}
SharedPreferences.Editor editor = context
.getSharedPreferences("mytest", 0).edit().clear();
for (Entry<String, String> entry : mapSchoolToLink.entrySet()) {
editor.putString(entry.getKey(), entry.getValue());
}
editor.commit();
}
});
return convertView;
}
public class ViewHolder {
TextView txtSchoolNameList;
public ImageView imgPhoto;
}
}
Activity
我必须为此隐藏BaseAdapter
任何解决方案的图像