I’m using ActionBarSherlock and a SherlockDialogFragment.
i have a little problem for my project,,i want to show other layout in sherlockdialogfragment,everything work well, my problem is,if i use imageadapter,as long as i know it should use “this” in imageadapter..but in public static “this” can’t used,how can it be?? i don’t understand how to show layout in sherlockdialogfragment..here is my problem..
((GridView) gridView).setAdapter(new ImageAdapter(this, MOBILE_OS));
and here is my full code
public static class MyDialogFragment extends SherlockDialogFragment {
int mNum;
static MyDialogFragment newInstance(int num) {
MyDialogFragment f = new MyDialogFragment();
Bundle args = new Bundle();
args.putInt("num", num);
f.setArguments(args);
return f;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mNum = getArguments().getInt("num");
int style = DialogFragment.STYLE_NORMAL, theme = 0;
style = DialogFragment.STYLE_NO_FRAME;
theme = android.R.style.Theme;
setStyle(style, theme);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final String[] MOBILE_OS = new String[] { "Android", "iOS",
"Windows", "Blackberry" };
View v = inflater.inflate(R.layout.pen_content, container, false);
View gridView = v.findViewById(R.id.gridView1);
((GridView) gridView).setAdapter(new ImageAdapter(this, MOBILE_OS));
return v;
}
}
what should i do to fix mycode…
thanks…
EDIT….my problem solved..but i ask one more….what should i do,if i want to result value from gridview event click?? i add setOnClickListener but i get error…
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final String[] MOBILE_OS = new String[] { "Android", "iOS",
"Windows", "Blackberry" };
View v = inflater.inflate(R.layout.pen_content, container, false);
View gridView = v.findViewById(R.id.gridView1);
((GridView) gridView).setAdapter(new ImageAdapter(getSherlockActivity(), MOBILE_OS));
gridView.setOnClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Toast.makeText(getSherlockActivity(),((TextView)v.findViewById(R.id.grid_item_label)).getText(), Toast.LENGTH_SHORT).show();
}
});
return v;
}
Change
So it is
You seem to have a type mismatch, a
SherlockFragmentdoes not extendContext, which your ImageAdapter probably needs.To attempt to answer your edited question:
You still need to use the GridView class when setting your listener. You should cast from the beginning like so: