android 在fragment里面怎么使用dialogfragment
1个回答
推荐于2016-01-08
展开全部
使用Fragment的Activity
MainActivity类要继承FragmentActivity,因为在下面getSupportFragmentManager要用到
public class MainActivity extends FragmentActivity {
public Button btn_search;
Fragment_Search dialogFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_search = (Button) findViewById(R.id.btn_search);
btn_search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
showSearchDialog();
}
});
}
protected void showSearchDialog() {
// Create and show the dialog.
if(dialogFragment == null)
dialogFragment = new Fragment_Search();
dialogFragment.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
dialogFragment.show(getSupportFragmentManager(), "dialog");
}
}
MainActivity类要继承FragmentActivity,因为在下面getSupportFragmentManager要用到
public class MainActivity extends FragmentActivity {
public Button btn_search;
Fragment_Search dialogFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_search = (Button) findViewById(R.id.btn_search);
btn_search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
showSearchDialog();
}
});
}
protected void showSearchDialog() {
// Create and show the dialog.
if(dialogFragment == null)
dialogFragment = new Fragment_Search();
dialogFragment.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
dialogFragment.show(getSupportFragmentManager(), "dialog");
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询