0
我使用ActionBarSherlock和SherlockDialogFragment。 我對我的項目有一點問題,我想在sherlockdialogfragment中顯示其他佈局,一切正常,我的問題是,如果我使用imageadapter,只要我知道它應該在imageadapter中使用「this」。但是在公共靜態「這個」不能使用,它怎麼可能?我不知道如何來顯示sherlockdialogfragment..here佈局是我的問題..SherlockDialogFragment充氣佈局?
((GridView) gridView).setAdapter(new ImageAdapter(this, MOBILE_OS));
,這裏是我的全部代碼
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;
}
}
我應該怎麼做才能解決mycode的... 謝謝...
編輯....我的問題解決了..但我問了一個更多....我應該怎麼做,如果我想要從gridview事件結果值單擊??我添加setOnClickListener,但我得到的錯誤...
@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;
}
我的問題是很容易的,我新受關於Java ...:d Ok..it的work..thanks ... – ltvie
@ltvie沒問題,你應該看一下java [tutorials](http://docs.oracle.com/javase/tutorial/),以便更好地掌握OOP。 –
我想問更多..(見編輯) – ltvie