我有一个ImageView
连续listview
的,当我点击一个方法总是返回时。imageView
clickevent
imageview
getTag()
null
我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_marginRight="80dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/filename_mainlist"
android:layout_below="@+id/filename_mainlist"
android:layout_marginTop="0dip"
android:max="100"
/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/text" />
<TextView
android:id="@+id/filename_mainlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="17dp"
android:layout_toRightOf="@+id/imageView1"
android:text="filename_mainlist" />
<TextView
android:id="@+id/filesize_maillist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progressBar1"
android:layout_below="@+id/progressBar1"
android:text="filesize" />
<ImageView
android:id="@+id/actionitem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/list_dropdown"
android:clickable="true"
android:onClick="ListActionitemclick"
/>
</RelativeLayout>
我的自定义光标适配器:
public class CustomCursorAdapter extends CursorAdapter {
private final int KB = 1024;
private final int MG = KB * KB;
private final int GB = MG * KB;
private String display_size;
public CustomCursorAdapter(Context context, Cursor c, boolean autoRequery) {
super(context, c, autoRequery);
// TODO Auto-generated constructor stub
}
@Override
public void bindView(View arg0, Context arg1, Cursor arg2) {
// TODO Auto-generated method stub
viewholder holder= (viewholder)arg0.getTag();
holder.filename.setText(arg2.getString(arg2.getColumnIndex(arg2.getColumnName(1))));
holder.filesize.setText(arg2.getString(arg2.getColumnIndex(arg2.getColumnName(2))));
holder.icon.setImageDrawable(Util.getIcon(mContext, filetype));
holder.progress.setProgress(arg2.getInt(arg2.getColumnIndex(arg2.getColumnName(3))));
}
@Override
public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
LayoutInflater inflater = LayoutInflater.from(arg0);
View retView = inflater.inflate(R.layout.mainlist_row,null);
viewholder holder = new viewholder();
holder.filename=(TextView)retView.findViewById(R.id.filename_mainlist);
holder.filesize=(TextView)retView.findViewById(R.id.filesize_maillist);
holder.icon=(ImageView)retView.findViewById(R.id.imageView1);
holder.dropdownicon=(ImageView)retView.findViewById(R.id.actionitem);
holder.progress=(ProgressBar)retView.findViewById(R.id.progressBar1);
retView.setTag(holder);
return retView;
}
class viewholder
{
TextView filename;
TextView filesize;
ImageView icon;
ImageView dropdownicon;
ProgressBar progress;
}
}
动作项点击事件:
public void ListActionitemclick(View v)
{
mSelectedRow = (Integer)v.getTag();// i am always getting a null value here
mQuickAction.show(v);
}
请帮我解决这个问题提前谢谢。