最近做的launcher项目里一个显示对话框效果。好多朋友都问我要代码,所以今天抽了点时间把这段代码扣出来,分享给大家《转帖的朋友,请标明出处,尊重作者的劳动成果》。上图吧
代码相对较多些,我就不一一阐述。项目里抠出来的,一些没必要的也都在里边了。使用作法如下
- public class MainActivity extends Activity implements OnCorpusSelectedListener {
- public CorpusSelectionDialog mCorpusSelectionDialog;
- private List<Corpus> mAppCategoryList;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- initData();
- Button b = (Button) this.findViewById(R.id.button1);
- b.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- showCorpusSelectionDialog();
- }
- });
- }
- @Override
- public void onCorpusSelected(Corpus corpus) {
- Toast.makeText(this, corpus.label + "被点了", Toast.LENGTH_LONG).show();
- }
- /**
- * 显示自定义dialog
- */
- protected void showCorpusSelectionDialog() {
- if (mCorpusSelectionDialog == null) {
- mCorpusSelectionDialog = new CategoryAppDialog(this,
- mAppCategoryList);
- mCorpusSelectionDialog.setOwnerActivity(this);
- mCorpusSelectionDialog.setOnCorpusSelectedListener(this);
- }
- mCorpusSelectionDialog.show();
- }