`
coolerbaosi
  • 浏览: 729351 次
文章分类
社区版块
存档分类
最新评论

Dialog demo

 
阅读更多
(1)对话框实现,之我是怎么想的,没有排序,立即就上去做,这样的结果浪费了时间和精力。过程如下:




String usbRootPath = UrlUtil.getUSBDirectoryRoot();
LinkedList<Node> usbData = loadData(usbRootPath);
usbData.add(new Node(getResources().getString(R.string.sdcard),UrlUtil.getSdcardDirectory()));

View dialogLayout = LayoutInflater.from(getApplicationContext()).inflate(R.layout.dialog, null);
ListView listView = (ListView) dialogLayout.findViewById(R.id.dialog_lv);
dialogLayout.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
//close dialog
}
});


StoreDeviceAdapter adapter = new StoreDeviceAdapter(getApplicationContext(), usbData);
listView.setAdapter(adapter);


listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {


@Override
public void onItemClick(AdapterView<?> paramAdapterView, View parentView, int position, long paramLong) {
//to do Item click.

}
});

AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
// alertDialog.setTitle(R.layout.dialog_title_item);
// alertDialog.setIcon(android.R.drawable.ic_dialog_info);
alertDialog.setCustomTitle(LayoutInflater.from(getApplicationContext()).inflate(R.layout.dialog_title_item, null));
alertDialog.setView(dialogLayout);
alertDialog.show();
alertDialog.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
}

});






我应该怎么做才是最好的?


改进:


完善:




(2)
必须先安装
http://asyty.iteye.com/blog/1440141


xiongmc@xiongmc-desktop:~$ scp /home/xiongmc/下载/jdk/jdk-6u45-linux-x64.bin jianjun@172.21.107.29:/home/jianjun/jdk


(2.-1)AlertDailog 发现无法满足需求,于是向走2.1。




(2.1)使用对话框。对话框也无法满足需求,于是3.0
Dialog dialog = new Dialog(MainActivity.this);

// setContentView可以设置为一个View也可以简单地指定资源ID
// LayoutInflater
// li=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
// View v=li.inflate(R.layout.dialog_layout, null);
// dialog.setContentView(v);
dialog.setContentView(R.layout.dialog);


// dialog.setTitle("Custom Dialog");
/*
* 获取圣诞框的窗口对象及参数对象以修改对话框的布局设置,
* 可以直接调用getWindow(),表示获得这个Activity的Window
* 对象,这样这可以以同样的方式改变这个Activity的属性.
*/
Window dialogWindow = dialog.getWindow();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
dialogWindow.setGravity(Gravity.CENTER);


(3.0)PopupWindow 我是如何使用的?



View dialogLayout = LayoutInflater.from(getApplicationContext()).inflate(R.layout.dialog, null);

PopupWindow popupWindow = new PopupWindow(dialogLayout,400,400, true);


ListView listView = (ListView) dialogLayout.findViewById(R.id.dialog_lv);




改进


popupWindow.showAtLocation(v, Gravity.RIGHT|Gravity.BOTTOM, 0, 0);




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics