我有,我有一個TextView和ImageView的 現在我想隱藏或在ListView ONY一些項目顯示ImageView的自定義列表視圖。在自定義列表視圖動態隱藏查看Android中
我已經完成了這個使用getview方法,但問題是,當第一次顯示列表視圖時,視圖不會隱藏,但當我向下滾動並向上滾動時,它會被隱藏。以下是代碼片段。提前致謝。
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
ViewHolder holder;
if (v != convertView && v != null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.jazzartist, null);
holder.albumsView = (TextView)convertView.findViewById(R.id.artist_albums_textview);
v.setTag(holder);
}
else{
holder = (ViewHolder) convertView.getTag(); }
ViewHolder holder1 = (ViewHolder) v.getTag();
holder1.objimg = (ImageView)convertView.findViewById(R.id.drag);
if(position == 4){
(holder1.objimg).setVisibility(View.INVISIBLE); // here I am hiding Imageview for position 4
}
else
{
(holder1.objimg).setVisibility(View.VISIBLE); // here I am showing Imageview for rest of items
}
String albums = getItem(position).albums;
holder1.albumsView.setText(albums);
return v;
}
}
}
不使用此行.. 視圖V = super.getView(位置,convertView,親本); 使用View v = convertView;如果 – SilentKiller 2012-08-14 10:13:03
應用程序崩潰我刪除行 – kendrelaxman 2012-08-14 10:33:55
嘗試通過Braj給出的代碼......也不錯的多數民衆贊成代碼.. – SilentKiller 2012-08-14 10:35:41