我试图FragmentActivity
在bindView
. CursorAdapter
实际上,我正在尝试在我的 中单击DialogFragment
an 时创建一个,与.ImageView
ListView
SimpleCursorAdapter
@Override
public void bindView(View view, Context context, Cursor c) {
super.bindView(view, context, c);
ImageView geoEditIcon = (ImageView)view.findViewById(R.id.li_cdf_icon_geoedit);
geoEditIcon.setImageResource(R.drawable.geolist_edit);
geoEditIcon.setTag(c.getString(c.getColumnIndex(DBConstants.ID)));
geoEditIcon.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Log.i("geolist", "geoEditIcon clicked");
String selectedGeoID = v.getTag().toString();
Log.i("geolist", "geoEditIcon selected Id->"+selectedGeoID);
EditGeofenceFragment editGeofenceFragment = new EditGeofenceFragment(v.getContext(),selectedGeoID);
//what context i want to use in Show method
editGeofenceFragment.show(getActivity().getSupportFragmentManager(), "editGeofenceFragment");
}
});
}
更新 :
我已将 getSupportFragmentManager 引用传递给 MySimpleCursorAdapter 的构造函数,并在我的匿名内部类中使用它。这就是我的对话框片段显示方法。现在它工作正常。我在下面更新了我的代码。
public MySimpleCursorAdapter(Context context, FragmentManager fragmentManager, int layout, Cursor c,String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
this.context=context;
this.fragmentManager=fragmentManager;
}
@Override
public void bindView(View view, Context context, Cursor c) {
super.bindView(view, context, c);
ImageView geoEditIcon = (ImageView)view.findViewById(R.id.li_cdf_icon_geoedit);
geoEditIcon.setImageResource(R.drawable.geolist_edit);
geoEditIcon.setTag(c.getString(c.getColumnIndex(DBConstants.ID)));
geoEditIcon.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Log.i("geolist", "geoEditIcon clicked");
String selectedGeoID = v.getTag().toString();
Log.i("geolist", "geoEditIcon selected Id->"+selectedGeoID);
EditGeofenceFragment editGeofenceFragment = new EditGeofenceFragment(v.getContext(),selectedGeoID);
// Put fragmentManager in first parameter to show method.
editGeofenceFragment.show(fragmentManager, "editGeofenceFragment");
}
});
}