android – 无法更改ImageView的可见性

前端之家收集整理的这篇文章主要介绍了android – 无法更改ImageView的可见性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个ListView使用自定义cursoradapter来填充ListView.

row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

   <LinearLayout
       android:orientation="vertical"
       android:layout_width="0dip"
       android:layout_weight="1"
       android:layout_height="fill_parent">
       <TextView
           android:id="@+id/title"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:singleLine="true"
           android:gravity="center_vertical"
           android:ellipsize="marquee"
           android:textSize="24dp" />
       <TextView
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:id="@+id/artist"
           android:singleLine="true"
           android:ellipsize="marquee"
           android:textSize="14dp" />
    </LinearLayout>
    <ImageView
       android:id="@+id/currentplaying"
       android:layout_width="wrap_content"
       android:layout_height="fill_parent"
       android:layout_marginLeft="1dip"
       android:src="@android:drawable/ic_media_play"
       android:contentDescription="@string/now_playing"
       android:visibility="gone" />
</LinearLayout>

如您所见,ImageView的可见性消失了.我想成功
对于一个特定行可见.这是我尝试的代码,但事实并非如此
工作…

View view = getListView().getAdapter().getView(0,null,null);
ImageView iv = (ImageView)view.findViewById(R.id.currentplaying);
iv.setVisibility(ImageView.VISIBLE);

提前致谢.

@Override
public View getView(int position,View convertView,ViewGroup parent) {
    ViewHolder holder;
    if(convertView==null) {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.yourlayout,null);
        holder.imgViewlogo = (ImageView) convertView.findViewById(R.id.imgViewlogo);
        convertView.setTag(holder);
    }
    else {
        holder=(ViewHolder)convertView.getTag();
    }
    if(position==0) {     
        holder.imgViewlogo.setVisiblity(View.VISIBLE);
    }
    return convertView;
}

编辑:

我搞定了.我用它来启动ListView活动.

intent.putExtra("id",c.getInt(c.getColumnIndex(DatabaseHelper._ID)));
startActivity(intent);

在ListView活动中,

currentplayingid = getIntent().getExtras().getInt("id");

然后我在bindview()中添加了这个

ImageView imgview = (ImageView)view.findViewById(R.id.currentplaying);
int id = c.getInt(c.getColumnIndex(DatabaseHelper._ID));
if (id == SongsListActivity.this.currentplayingid)
    imgview.setVisibility(View.VISIBLE);
else
    imgview.setVisibility(View.GONE);

解决方法

我搞定了.我用它来启动列表视图活动.
intent.putExtra("id",c.getInt(c.getColumnIndex(DatabaseHelper._ID)));
startActivity(intent);

在listview活动中,

currentplayingid = getIntent().getExtras().getInt("id");

然后我在bindview()中添加了这个

ImageView imgview = (ImageView)view.findViewById(R.id.currentplaying);
int id = c.getInt(c.getColumnIndex(DatabaseHelper._ID));
if ( id == SongsListActivity.this.currentplayingid )
imgview.setVisibility(View.VISIBLE);
else
imgview.setVisibility(View.GONE);
原文链接:https://www.f2er.com/android/318538.html

猜你在找的Android相关文章