Android自定義樣式對話框Dialog

WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();

final AlertDialog ab = new AlertDialog.Builder(mContext).create();
ab.show();//必須在getWindow()之前
Window window = ab.getWindow();
window.setContentView(R.layout.dialog_select_time_period);
WindowManager.LayoutParams lp = window.getAttributes();
//lp.y=800;
window.setLayout((int) (width*0.8),(int) (height*0.8));//WindowManager.LayoutParams.WRAP_CONTENT
window.setGravity(Gravity.CENTER);
window.setAttributes(lp);

lv_time = (ListView) window.findViewById(R.id.lv_time);

mAdapter = new SelectTimePeriodAdapter(mContext,times,tvOrderDatetime.getText().toString());
lv_time.setAdapter(mAdapter);
lv_time.setSelection(DateUtil.getCurrentHour());   
mAdapter.notifyDataSetChanged();

lv_time.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {
        Time time = times.get(position);
        int[] pos = mAdapter.getPosition();
        for (int i = 0; i < pos.length; i++)
        {
            if (position==pos[position]||time.getExpectNum()==time.getBuslimit())
            {
                return;
            }else {
                //String period = getArr()[position];
                tv_period.setText(time.getExpectTimeStr());
                ab.dismiss();
            }
        }
發佈了40 篇原創文章 · 獲贊 37 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章