如何在显示警报对话框时减少延迟

时间:2016-06-21 10:54:10

标签: android

我希望在显示警告对话框时减少延迟

private void createAlertDialog() {


    AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
    LayoutInflater inflater = LayoutInflater.from(context);
    SearchView searchView;

    View dialogView = inflater.inflate(R.layout.search_view, null);
    searchView = (SearchView) dialogView.findViewById(R.id.search_pop);
    listView = (ListView) dialogView.findViewById(R.id.search_list);
    SearchViewStyle.on(searchView)
            .setCursorColor(R.color.white)
            //.setTextColor(R.color.white)
            .setHintTextColor(getResources().getColor(R.color.black))
            .setSearchHintDrawable(R.drawable.search_icon, "Search Here")
            .setSearchButtonImageResource(R.drawable.search_icon)
            .setSubmitAreaDrawableId(R.drawable.abc_textfield_search_activated_mtrl_alpha)
            .setCloseBtnImageResource(R.drawable.circle_close_btn);

    builder.setView(dialogView);
    searchView.setOnQueryTextListener(listener); // call the QuerytextListner.



    alert = builder.create();
    alert.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    final Window window = alert.getWindow();
    WindowManager.LayoutParams wmlp = alert.getWindow().getAttributes();

    wmlp.gravity = Gravity.TOP | Gravity.LEFT;
    // window.setGravity(Gravity.LEFT);

    lp.copyFrom(window.getAttributes());
    //This makes the dialog take up the full width

    lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    window.setAttributes(lp);


}

以上代码用于创建警报对话框 并在点击按钮时显示它

searchImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            alert.show();
            SearchAdapter searchAdapter = new SearchAdapter(results, getApplicationContext());
            listView.setAdapter(searchAdapter);


            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                    Log.i("itemClick", position + "");
                    alert.dismiss();

                    getInformation(position);


                }
            });


        }
    });

以下代码显示对话框。但问题是显示它滞后

0 个答案:

没有答案