我想从ListView
隐藏图像,在这里,我已经使用自定义列表视图与BaseAdapter
请参见下面的图像,这对Edit btn
图片点击1应该是可见的,隐藏图像BaseAdapter
的ListView图像是遵循
我已经对点击做到了这一点代码
++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
对象,这是什么按钮只有最后一个按钮隐形,因为它越来越最后引用的点击情况,我不想再reaload 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
这个
1:你想** **隐藏或使** **看不见?如果隐藏然后使用View.GONE,并且如果想使其不可见,那么使用View.INVISIBLE –
确切多数民众赞成我想要做 –
使用baseAdapter.holder.imgPhoto.setVisibility(ImageView.GONE); –