i tryied to custom my ListView , so i use this item layout 「 list_item.xml」
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="10dp"
android:textSize="16dip"
android:textColor="#000000"
android:gravity="center_vertical"
android:background="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_weight="1">
</TextView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0"
android:background="#FFFFFF"
android:padding="10dip"
android:gravity="center_vertical">
<ImageView
android:id="@+id/pause"
android:src="@drawable/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="pauseBtn_onClick"
/>
<ImageView
android:id="@+id/play"
android:src="@drawable/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="playBtn_onClick"/>
</RelativeLayout>
</LinearLayout>
just as what you saw, there are 2 images in this layout, what i wanna do is,
when user click any item , the play_icon(the second image in the listview item) , will
开发者_Go百科disappear.
so i write code as the following :
mp3_listView.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View _view, int index , long arg3)
{
String _url = musicList.get(index).get("link").toString();
LinearLayout _container = (LinearLayout)mp3_listView.getChildAt(index);
RelativeLayout _container2 = (RelativeLayout) _container.getChildAt(1);
ImageView img = (ImageView)_container2.getChildAt(1);
img.setVisibility(View.INVISIBLE);
Toast.makeText(tabDigTest.this , "GG : "+_container.findViewById(R.id.play) , Toast.LENGTH_SHORT).show();
}
}
but something strange occurred .... more than one item's img be hidden because of the:
img.setVisibility(View.INVISIBLE);
i don't why because i only set one img to INVISIBLE ......i think i need help O_o
To retrieve the user click, I guess you set up an OnItemClickListener.
ListView lv = (fecth your list vieW)
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//you might want to use 'view' here
}
});
In the onItemClick method, the view parameter is the view you returned in your ListAdapter's getView method. So if say, you have returned a LinearLayout containing three childrens with id ("textview", "imageview1", "imageview2"), you would simply call view.findViewById(R.id.imageview1) to retrieve the first ImageView.
精彩评论