Ama*_*lam 5 android android-listview
我有一个ListView,其行由我格式化.每行都有ImageView和TextView的混合.我也实现了自己的适配器,并能够通过它绘制每一行.
现在,我想要这样的东西 -
我为此尝试了很多东西,并希望我的代码尽可能高效(就过度杀伤而言).目前我只能捕获特定ImageView上的click事件,但我不知道单击了哪一行.
我在Row XML中提供了一个属性,如下所示 -
<ImageView android:id="@+id/user_image"
android:padding="5dip"
android:layout_height="60dip"
android:layout_width="60dip"
android:clickable="true"
android:onClick="uImgClickHandler"/>
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我有一个像这样的方法:
public void uImgClickHandler(View v){
Log.d("IMG CLICKED", ""+v.getId());
LinearLayout parentRow = (LinearLayout)v.getParent();
}
Run Code Online (Sandbox Code Playgroud)
我可以得到父行(也许),但我不确定如何从这里走得更远.有人可以帮忙吗?
Lab*_*lan 14
请参考这个,
我只是编写代码来给你提供想法,格式不正确
class youaddaper extends BaseAdapter{
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflate = LayoutInflater.from(context);
View v = inflate.inflate(id, parent, false);
ImageView imageview = (ImageView) v.findViewById(R.id.imageView);
imageview.setOnClickListener(new imageViewClickListener(position));
//you can pass what ever to this class you want,
//i mean, you can use array(postion) as per the logic you need to implement
}
class imageViewClickListener implements OnClickListener {
int position;
public imageViewClickListener( int pos)
{
this.position = pos;
}
public void onClick(View v) {
{// you can write the code what happens for the that click and
// you will get the selected row index in position
}
}
Run Code Online (Sandbox Code Playgroud)
}
希望它能帮助你