ListView 中使用setvisibility方法不起作用

RogerHan 发布于 2013/08/21 17:56
阅读 4K+
收藏 0
如题为一个ListView绑定了setOnItemClickListener监听事件,在该监听事件中对一个图片进行显示或者隐藏的处理。

代码片段如下:

firstInfoList = (ListView) findViewById(R.id.categorylist);
JobTypeInfoAdapter jobTypeInfoAdapter = new JobTypeInfoAdapter(this,infoList);
firstInfoList.setAdapter(jobTypeInfoAdapter);
firstInfoList.setOnItemClickListener(new OnItemClickListener(){
    public void onItemClick(AdapterView<?> parent, View v,int position, long id){
	// TODO Auto-generated method stub
	if(v.findViewById(R.id.common_simple_delete_selected).getVisibility()==View.GONE)
        {
	    v.findViewById(R.id.common_simple_delete_selected).setVisibility(View.VISIBLE);
	}
	else if(v.findViewById(R.id.common_simple_delete_selected).getVisibility()==View.VISIBLE)
	{
	    v.findViewById(R.id.common_simple_delete_selected).setVisibility(View.GONE);
	}		
}
});
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:background="@color/closewhite"
    android:orientation="vertical" >
    <RelativeLayout android:id="@+id/job_type_info" android:background="@android:drawable/list_selector_background" android:layout_height="44.0dip" android:orientation="vertical"  android:gravity="center_vertical"  android:layout_width="fill_parent">
        <TextView android:id="@+id/jobtype_first_category" android:focusable="false" style="@style/searche_job_select_second_title_style" />
        <ImageView android:id="@+id/common_simple_delete_selected" android:focusable="false" android:visibility="invisible" android:src="@drawable/munti_data_item_selected" style="@style/common_listitem_arrow_style" />
    </RelativeLayout>
</LinearLayout>

其中的setVisbility()方法不起作用,请问这是为什么呢?


加载中
0
kenping
kenping
初始状态是invisible,你的两个if都进不去
RogerHan
RogerHan
我错了。
返回顶部
顶部