Example usage for android.app Dialog setContentView

List of usage examples for android.app Dialog setContentView

Introduction

In this page you can find the example usage for android.app Dialog setContentView.

Prototype

public void setContentView(@NonNull View view) 

Source Link

Document

Set the screen content to an explicit view.

Usage

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void editRemoteProfile(String prof_act, String prof_name, String prof_user, String prof_pass,
        String prof_addr, final String prof_port, String prof_share, String msg_text, final int item_num) {

    // ??//from  w w w  . ja v a  2s  .co m
    final Dialog dialog = new Dialog(this);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.edit_remote_profile);
    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.remote_profile_dlg_msg);

    if (msg_text.length() != 0) {
        dlg_msg.setText(msg_text);
    }

    dialog.setTitle("Edit remote profile");

    CommonDialog.setDlgBoxSizeLimit(dialog, false);

    final EditText editname = (EditText) dialog.findViewById(R.id.remote_profile_name);
    editname.setText(prof_name);
    final EditText editaddr = (EditText) dialog.findViewById(R.id.remote_profile_addr);
    editaddr.setText(prof_addr);
    final EditText edituser = (EditText) dialog.findViewById(R.id.remote_profile_user);
    edituser.setText(prof_user);
    final EditText editpass = (EditText) dialog.findViewById(R.id.remote_profile_pass);
    editpass.setText(prof_pass);
    final EditText editshare = (EditText) dialog.findViewById(R.id.remote_profile_share);
    editshare.setText(prof_share);
    final EditText editport = (EditText) dialog.findViewById(R.id.remote_profile_port_number);
    editport.setText(prof_port);

    final CheckBox tg = (CheckBox) dialog.findViewById(R.id.remote_profile_active);
    if (prof_act.equals("A"))
        tg.setChecked(true);
    else
        tg.setChecked(false);

    // address?
    Button btnAddr = (Button) dialog.findViewById(R.id.remote_profile_addrbtn);
    btnAddr.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    editaddr.setText((String) arg1[1]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    if (arg1 != null)
                        dlg_msg.setText((String) arg1[0]);
                    else
                        dlg_msg.setText("");
                }

            });
            scanRemoteNetworkDlg(ntfy, editport.getText().toString());
        }
    });

    Button btnGet1 = (Button) dialog.findViewById(R.id.remote_profile_get_btn1);
    btnGet1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String prof_addr, prof_user, prof_pass;
            editaddr.selectAll();
            prof_addr = editaddr.getText().toString();
            edituser.selectAll();
            prof_user = edituser.getText().toString();
            editpass.selectAll();
            prof_pass = editpass.getText().toString();

            setJcifsProperties(prof_user, prof_pass);

            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    if (!((String) arg1[0]).equals(""))
                        editshare.setText((String) arg1[0]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    dlg_msg.setText((String) arg1[0]);
                }

            });
            setRemoteShare(prof_user, prof_pass, prof_addr, ntfy);
        }
    });

    // CANCEL?
    final Button btnCancel = (Button) dialog.findViewById(R.id.remote_profile_cancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            //            setFixedOrientation(false);
        }
    });
    // OK?
    Button btnOK = (Button) dialog.findViewById(R.id.remote_profile_ok);
    btnOK.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String new_user, new_pass, new_addr, new_share, new_act, new_name;

            dialog.dismiss();
            //            setFixedOrientation(false);

            new_addr = editaddr.getText().toString();
            new_user = edituser.getText().toString();
            new_pass = editpass.getText().toString();
            new_share = editshare.getText().toString();
            new_name = editname.getText().toString();
            String new_port = editport.getText().toString();

            if (tg.isChecked())
                new_act = "A";
            else
                new_act = "I";

            int pos = profileListView.getFirstVisiblePosition();
            int topPos = 0;
            if (profileListView.getChildAt(0) != null)
                profileListView.getChildAt(0).getTop();
            ProfileListItem item = profileAdapter.getItem(item_num);

            profileAdapter.remove(item);
            profileAdapter.insert(new ProfileListItem("R", new_name, new_act, new_user, new_pass, new_addr,
                    new_port, new_share, false), item_num);

            saveProfile(false, "", "");
            //            appendProfile();
            //            profileAdapter = 
            //                  createProfileList(false); // create profile list
            profileListView.setSelectionFromTop(pos, topPos);
            profileAdapter.setNotifyOnChange(true);
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnCancel.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(currentContext));
    //      setFixedOrientation(true);
    //      dialog.setCancelable(false);
    dialog.show();

}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void addRemoteProfile(final String prof_act, final String prof_name, final String prof_user,
        final String prof_pass, final String prof_addr, final String prof_port, final String prof_share,
        final String msg_text) {

    // ??//from  ww w.jav  a2  s .  c  om
    final Dialog dialog = new Dialog(this);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.edit_remote_profile);
    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.remote_profile_dlg_msg);
    if (msg_text.length() != 0) {
        dlg_msg.setText(msg_text);
    }

    dialog.setTitle("Add remote profile");

    final EditText editname = (EditText) dialog.findViewById(R.id.remote_profile_name);
    editname.setText(prof_name);
    final EditText editaddr = (EditText) dialog.findViewById(R.id.remote_profile_addr);
    editaddr.setText(prof_addr);
    final EditText edituser = (EditText) dialog.findViewById(R.id.remote_profile_user);
    edituser.setText(prof_user);
    final EditText editpass = (EditText) dialog.findViewById(R.id.remote_profile_pass);
    editpass.setText(prof_pass);
    final EditText editshare = (EditText) dialog.findViewById(R.id.remote_profile_share);
    editshare.setText(prof_share);
    final EditText editport = (EditText) dialog.findViewById(R.id.remote_profile_port_number);
    editport.setText(prof_port);

    CommonDialog.setDlgBoxSizeCompact(dialog);

    final CheckBox tg = (CheckBox) dialog.findViewById(R.id.remote_profile_active);
    if (prof_act.equals("A"))
        tg.setChecked(true);
    else
        tg.setChecked(false);

    // address?
    Button btnAddr = (Button) dialog.findViewById(R.id.remote_profile_addrbtn);
    btnAddr.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    editaddr.setText((String) arg1[1]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    dlg_msg.setText("");
                }

            });
            scanRemoteNetworkDlg(ntfy, editport.getText().toString());
        }
    });

    final Button btnGet1 = (Button) dialog.findViewById(R.id.remote_profile_get_btn1);
    btnGet1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            btnGet1.setEnabled(false);
            String prof_addr, prof_user, prof_pass;
            editaddr.selectAll();
            prof_addr = editaddr.getText().toString();
            edituser.selectAll();
            prof_user = edituser.getText().toString();
            editpass.selectAll();
            prof_pass = editpass.getText().toString();

            setJcifsProperties(prof_user, prof_pass);

            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    if (!((String) arg1[0]).equals(""))
                        editshare.setText((String) arg1[0]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    dlg_msg.setText((String) arg1[0]);
                }

            });
            setRemoteShare(prof_user, prof_pass, prof_addr, ntfy);
        }
    });

    // CANCEL?
    final Button btnCancel = (Button) dialog.findViewById(R.id.remote_profile_cancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            //            setFixedOrientation(false);
        }
    });
    // OK?
    Button btnOK = (Button) dialog.findViewById(R.id.remote_profile_ok);
    btnOK.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String new_act, new_name;
            editaddr.selectAll();
            edituser.selectAll();
            editpass.selectAll();
            editshare.selectAll();
            editname.selectAll();
            new_name = editname.getText().toString();

            if (tg.isChecked())
                new_act = "A";
            else
                new_act = "A";

            if (isProfileDuplicated("R", new_name)) {
                dlg_msg.setText(getString(R.string.msgs_add_remote_profile_duplicate));
            } else {
                dialog.dismiss();
                //               setFixedOrientation(false);
                int pos = profileListView.getFirstVisiblePosition();
                int topPos = 0;
                if (profileListView.getChildAt(0) != null)
                    profileListView.getChildAt(0).getTop();
                String prof_user = edituser.getText().toString();
                String prof_pass = editpass.getText().toString();
                String prof_addr = editaddr.getText().toString();
                String prof_share = editshare.getText().toString();
                String prof_port = editport.getText().toString();
                profileAdapter.add(new ProfileListItem("R", new_name, new_act, prof_user, prof_pass, prof_addr,
                        prof_port, prof_share, false));
                saveProfile(false, "", "");
                profileAdapter = createProfileList(false, ""); // create profile list

                profileListView.setSelectionFromTop(pos, topPos);
                profileAdapter.setNotifyOnChange(true);

                setRemoteDirBtnListener();
            }
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnCancel.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(currentContext));
    //      setFixedOrientation(true);
    //      dialog.setCancelable(false);
    dialog.show();
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void setRemoteShare(final String prof_user, final String prof_pass, final String prof_addr,
        final NotifyEvent p_ntfy) {
    final ArrayList<String> rows = new ArrayList<String>();

    NotifyEvent ntfy = new NotifyEvent(mContext);
    ntfy.setListener(new NotifyEventListener() {
        @Override/* www.  java  2  s . com*/
        public void positiveResponse(Context c, Object[] o) {
            FileListAdapter tfl = (FileListAdapter) o[0];

            for (int i = 0; i < tfl.getCount(); i++) {
                FileListItem item = tfl.getItem(i);
                if (item.isDir() && item.canRead() && !item.getName().startsWith("IPC$")) {
                    String tmp = item.getName();
                    rows.add(tmp);
                }
            }
            if (rows.size() < 1)
                rows.add(getString(R.string.msgs_no_shared_resource));

            //??
            final Dialog dialog = new Dialog(c);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(false);
            dialog.setContentView(R.layout.item_select_list_dlg);
            ((TextView) dialog.findViewById(R.id.item_select_list_dlg_title)).setText("Select remote share");
            ((TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle)).setText("");

            CommonDialog.setDlgBoxSizeLimit(dialog, false);

            ListView lv = (ListView) dialog.findViewById(android.R.id.list);
            lv.setAdapter(new ArrayAdapter<String>(c, R.layout.simple_list_item_1m, rows));
            lv.setScrollingCacheEnabled(false);
            lv.setScrollbarFadingEnabled(false);

            lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
                    if (rows.get(idx).startsWith("---"))
                        return;
                    dialog.dismiss();
                    // ????????
                    p_ntfy.notifyToListener(true, new Object[] { rows.get(idx).toString() });
                }
            });
            //CANCEL?
            final Button btnCancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn);
            btnCancel.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    dialog.dismiss();
                    p_ntfy.notifyToListener(true, new Object[] { "" });
                }
            });
            // Cancel?
            dialog.setOnCancelListener(new Dialog.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface arg0) {
                    btnCancel.performClick();
                }
            });
            //              dialog.setOnKeyListener(new DialogOnKeyListener(currentContext));
            //              dialog.setCancelable(false);
            dialog.show();
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            p_ntfy.notifyToListener(false, new Object[] { "Remote file list creation error" });
        }
    });
    createRemoteFileList("smb://" + prof_addr + "/", ntfy);
    return;
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void showFileListCache(final ArrayList<FileListCacheItem> fcl, final FileListAdapter fla,
        final ListView flv, final Spinner spinner) {
    // ??//from w  ww  .  j  av  a 2  s . co  m
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.select_file_cache_dlg);
    //      final Button btnOk = 
    //            (Button) dialog.findViewById(R.id.select_file_cache_dlg_ok);
    final Button btnCancel = (Button) dialog.findViewById(R.id.select_file_cache_dlg_cancel);

    CommonDialog.setDlgBoxSizeCompact(dialog);

    ((TextView) dialog.findViewById(R.id.select_file_cache_dlg_title)).setText("Select file cache");

    ListView lv = (ListView) dialog.findViewById(R.id.select_file_cache_dlg_listview);

    final ArrayList<String> list = new ArrayList<String>();
    for (int i = 0; i < fcl.size(); i++) {
        list.add(fcl.get(i).directory);
    }
    Collections.sort(list, new Comparator<String>() {
        @Override
        public int compare(String lhs, String rhs) {
            return lhs.compareToIgnoreCase(rhs);
        }
    });
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, R.layout.simple_list_item_1o, list);
    lv.setAdapter(adapter);

    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String t_dir = list.get(position);
            FileListCacheItem dhi = getFileListCache(t_dir, fcl);
            if (dhi != null) {
                mIgnoreSpinnerSelection = true;
                int s_no = -1;
                for (int i = 0; i < spinner.getCount(); i++) {
                    if (spinner.getItemAtPosition(i).toString().equals(dhi.profile_name)) {
                        s_no = i;
                        break;
                    }
                }
                fla.setDataList(dhi.file_list);
                fla.notifyDataSetChanged();
                if (currentTabName.equals(SMBEXPLORER_TAB_LOCAL)) {
                    localBase = dhi.base;
                    if (dhi.base.equals(dhi.directory))
                        localDir = "";
                    else
                        localDir = dhi.directory.replace(localBase + "/", "");
                    replaceDirHist(localDirHist, dhi.directory_history);
                    setFilelistCurrDir(localFileListDirSpinner, localBase, localDir);
                    setFileListPathName(localFileListPathBtn, localFileListCache, localBase, localDir);
                    setEmptyFolderView();
                    localCurrFLI = dhi;
                    flv.setSelection(0);
                    for (int j = 0; j < localFileListView.getChildCount(); j++)
                        localFileListView.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);
                    localFileListReloadBtn.performClick();
                } else if (currentTabName.equals(SMBEXPLORER_TAB_REMOTE)) {
                    remoteBase = dhi.base;
                    if (dhi.base.equals(dhi.directory))
                        remoteDir = "";
                    else
                        remoteDir = dhi.directory.replace(remoteBase + "/", "");
                    replaceDirHist(remoteDirHist, dhi.directory_history);
                    setFilelistCurrDir(remoteFileListDirSpinner, remoteBase, remoteDir);
                    setFileListPathName(remoteFileListPathBtn, remoteFileListCache, remoteBase, remoteDir);
                    setEmptyFolderView();
                    remoteCurrFLI = dhi;
                    flv.setSelection(0);

                    //                  Log.v("","base="+remoteBase+", dir="+remoteDir+", histsz="+remoteDirHist.size());
                    for (int j = 0; j < remoteFileListView.getChildCount(); j++)
                        remoteFileListView.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);
                    if (remoteDir.equals("")) {
                        remoteFileListTopBtn.setEnabled(false);
                        remoteFileListUpBtn.setEnabled(false);
                    } else {
                        remoteFileListTopBtn.setEnabled(true);
                        remoteFileListUpBtn.setEnabled(true);
                    }
                }

                if (s_no != -1)
                    spinner.setSelection(s_no);
                Handler hndl = new Handler();
                hndl.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mIgnoreSpinnerSelection = false;
                    }
                }, 100);
                dialog.dismiss();
            }
        }
    });

    btnCancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    dialog.show();

}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

public void scanRemoteNetworkDlg(final NotifyEvent p_ntfy, String port_number) {
    //??//from w  w  w  .  j a  va  2s . c o m
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.scan_remote_ntwk_dlg);
    final Button btn_scan = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_ok);
    final Button btn_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_cancel);
    final TextView tvmsg = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_msg);
    final TextView tv_result = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_scan_result_title);
    tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_press_scan_btn));
    tv_result.setVisibility(TextView.GONE);

    final String from = getLocalIpAddress();
    String subnet = from.substring(0, from.lastIndexOf("."));
    String subnet_o1, subnet_o2, subnet_o3;
    subnet_o1 = subnet.substring(0, subnet.indexOf("."));
    subnet_o2 = subnet.substring(subnet.indexOf(".") + 1, subnet.lastIndexOf("."));
    subnet_o3 = subnet.substring(subnet.lastIndexOf(".") + 1, subnet.length());
    final EditText baEt1 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o1);
    final EditText baEt2 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o2);
    final EditText baEt3 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o3);
    final EditText baEt4 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o4);
    final EditText eaEt4 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_end_address_o4);
    baEt1.setText(subnet_o1);
    baEt2.setText(subnet_o2);
    baEt3.setText(subnet_o3);
    baEt4.setText("1");
    baEt4.setSelection(1);
    eaEt4.setText("254");
    baEt4.requestFocus();

    final CheckBox cb_use_port_number = (CheckBox) dialog.findViewById(R.id.scan_remote_ntwk_use_port);
    final EditText et_port_number = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_port_number);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    if (port_number.equals("")) {
        et_port_number.setEnabled(false);
        cb_use_port_number.setChecked(false);
    } else {
        et_port_number.setEnabled(true);
        et_port_number.setText(port_number);
        cb_use_port_number.setChecked(true);
    }
    cb_use_port_number.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            et_port_number.setEnabled(isChecked);
        }
    });

    final NotifyEvent ntfy_lv_click = new NotifyEvent(mContext);
    ntfy_lv_click.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            dialog.dismiss();
            p_ntfy.notifyToListener(true, o);
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
        }
    });

    final ArrayList<ScanAddressResultListItem> ipAddressList = new ArrayList<ScanAddressResultListItem>();
    //      ScanAddressResultListItem li=new ScanAddressResultListItem();
    //      li.server_name=mContext.getString(R.string.msgs_ip_address_no_address);
    //      ipAddressList.add(li);
    final ListView lv = (ListView) dialog.findViewById(R.id.scan_remote_ntwk_scan_result_list);
    final AdapterScanAddressResultList adap = new AdapterScanAddressResultList(mContext,
            R.layout.scan_address_result_list_item, ipAddressList, ntfy_lv_click);
    lv.setAdapter(adap);
    lv.setScrollingCacheEnabled(false);
    lv.setScrollbarFadingEnabled(false);

    //SCAN?
    btn_scan.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            ipAddressList.clear();
            NotifyEvent ntfy = new NotifyEvent(mContext);
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context c, Object[] o) {
                    if (ipAddressList.size() < 1) {
                        tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_not_detected));
                        tv_result.setVisibility(TextView.GONE);
                    } else {
                        tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_select_detected_host));
                        tv_result.setVisibility(TextView.VISIBLE);
                    }
                    //                   adap.clear();
                    //                   for (int i=0;i<ipAddressList.size();i++) 
                    //                      adap.add(ipAddressList.get(i));
                }

                @Override
                public void negativeResponse(Context c, Object[] o) {
                }

            });
            if (auditScanAddressRangeValue(dialog)) {
                tv_result.setVisibility(TextView.GONE);
                String ba1 = baEt1.getText().toString();
                String ba2 = baEt2.getText().toString();
                String ba3 = baEt3.getText().toString();
                String ba4 = baEt4.getText().toString();
                String ea4 = eaEt4.getText().toString();
                String subnet = ba1 + "." + ba2 + "." + ba3;
                int begin_addr = Integer.parseInt(ba4);
                int end_addr = Integer.parseInt(ea4);
                scanRemoteNetwork(dialog, lv, adap, ipAddressList, subnet, begin_addr, end_addr, ntfy);
            } else {
                //error
            }
        }
    });

    //CANCEL?
    btn_cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            p_ntfy.notifyToListener(false, null);
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btn_cancel.performClick();
        }
    });
    dialog.show();

}

From source file:it.sasabz.android.sasabus.fragments.OnlineSearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.inflater_glob = inflater;
    result = inflater.inflate(R.layout.online_search_layout, container, false);

    Date datum = new Date();
    SimpleDateFormat simple = new SimpleDateFormat("dd.MM.yyyy HH:mm");

    TextView datetime = (TextView) result.findViewById(R.id.time);
    String datetimestring = "";

    datetimestring = simple.format(datum);

    datetime.setText(datetimestring);//from   w  w w . ja  v  a2 s  .  com

    Button search = (Button) result.findViewById(R.id.search);

    search.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AutoCompleteTextView from = (AutoCompleteTextView) result.findViewById(R.id.from_text);
            AutoCompleteTextView to = (AutoCompleteTextView) result.findViewById(R.id.to_text);
            TextView datetime = (TextView) result.findViewById(R.id.time);

            String from_txt = getThis().getResources().getString(R.string.from_txt);

            if ((!from.getText().toString().trim().equals("")
                    || !from.getHint().toString().trim().equals(from_txt))
                    && !to.getText().toString().trim().equals("")) {
                //Intent getSelect = new Intent(getThis().getActivity(), OnlineSelectStopActivity.class);
                String fromtext = "";
                if (from.getText().toString().trim().equals(""))
                    fromtext = from.getHint().toString();
                else
                    fromtext = from.getText().toString();
                String totext = to.getText().toString();
                fromtext = "(" + fromtext.replace(" -", ")");
                totext = "(" + totext.replace(" -", ")");
                Fragment fragment = new OnlineSelectFragment(fromtext, totext, datetime.getText().toString());
                FragmentManager fragmentManager = getFragmentManager();
                FragmentTransaction ft = fragmentManager.beginTransaction();

                Fragment old = fragmentManager.findFragmentById(R.id.onlinefragment);
                if (old != null) {
                    ft.remove(old);
                }
                ft.add(R.id.onlinefragment, fragment);
                ft.addToBackStack(null);
                ft.commit();
                fragmentManager.executePendingTransactions();
            }
        }
    });

    datetime.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            // Create the dialog
            final Dialog mDateTimeDialog = new Dialog(getThis().getActivity());
            // Inflate the root layout
            final RelativeLayout mDateTimeDialogView = (RelativeLayout) inflater_glob
                    .inflate(R.layout.date_time_dialog, null);
            // Grab widget instance
            final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView
                    .findViewById(R.id.DateTimePicker);
            TextView dt = (TextView) result.findViewById(R.id.time);
            String datetimestring = dt.getText().toString();

            SimpleDateFormat datetimeformat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
            Date datetime = null;
            try {
                datetime = datetimeformat.parse(datetimestring);
            } catch (Exception e) {
                ;
            }
            mDateTimePicker.updateTime(datetime.getHours(), datetime.getMinutes());
            mDateTimePicker.updateDate(datetime.getYear() + 1900, datetime.getMonth(), datetime.getDate());
            // Check is system is set to use 24h time (this doesn't seem to
            // work as expected though)
            final String timeS = android.provider.Settings.System.getString(
                    getThis().getActivity().getContentResolver(), android.provider.Settings.System.TIME_12_24);
            final boolean is24h = !(timeS == null || timeS.equals("12"));

            ((Button) mDateTimeDialogView.findViewById(R.id.SetDateTime))
                    .setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            mDateTimePicker.clearFocus();
                            String datetimestring = "";
                            int day = mDateTimePicker.get(Calendar.DAY_OF_MONTH);
                            int month = mDateTimePicker.get(Calendar.MONTH) + 1;
                            int year = mDateTimePicker.get(Calendar.YEAR);
                            int hour = 0;
                            int min = 0;
                            int append = 0;
                            if (mDateTimePicker.is24HourView()) {
                                hour = mDateTimePicker.get(Calendar.HOUR_OF_DAY);
                                min = mDateTimePicker.get(Calendar.MINUTE);
                            } else {
                                hour = mDateTimePicker.get(Calendar.HOUR);
                                min = mDateTimePicker.get(Calendar.MINUTE);
                                if (mDateTimePicker.get(Calendar.AM_PM) == Calendar.AM) {
                                    append = 1;
                                } else {
                                    append = 2;
                                }
                            }
                            if (day < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += (day + ".");
                            if (month < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += (month + "." + year + " ");
                            if (hour < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += (hour + ":");
                            if (min < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += min;

                            switch (append) {
                            case 1:
                                datetimestring += " AM";
                                break;
                            case 2:
                                datetimestring += " PM";
                                break;
                            }

                            TextView time = (TextView) result.findViewById(R.id.time);
                            time.setText(datetimestring);
                            mDateTimeDialog.dismiss();
                        }
                    });
            // Cancel the dialog when the "Cancel" button is clicked
            ((Button) mDateTimeDialogView.findViewById(R.id.CancelDialog))
                    .setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimeDialog.cancel();
                        }
                    });

            // Reset Date and Time pickers when the "Reset" button is
            // clicked
            ((Button) mDateTimeDialogView.findViewById(R.id.ResetDateTime))
                    .setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimePicker.reset();
                        }
                    });

            // Setup TimePicker
            mDateTimePicker.setIs24HourView(is24h);
            // No title on the dialog window
            mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            // Set the dialog content view
            mDateTimeDialog.setContentView(mDateTimeDialogView);
            // Display the dialog
            mDateTimeDialog.show();
        }

    });

    ImageButton datepicker = (ImageButton) result.findViewById(R.id.datepicker);

    datepicker.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            // Create the dialog
            final Dialog mDateTimeDialog = new Dialog(getThis().getActivity());
            // Inflate the root layout
            final RelativeLayout mDateTimeDialogView = (RelativeLayout) inflater_glob
                    .inflate(R.layout.date_time_dialog, null);
            // Grab widget instance
            final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView
                    .findViewById(R.id.DateTimePicker);
            TextView dt = (TextView) result.findViewById(R.id.time);
            String datetimestring = dt.getText().toString();
            SimpleDateFormat datetimeformat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
            Date datetime = null;
            try {
                datetime = datetimeformat.parse(datetimestring);
            } catch (Exception e) {
                ;
            }
            mDateTimePicker.updateTime(datetime.getHours(), datetime.getMinutes());
            mDateTimePicker.updateDate(datetime.getYear() + 1900, datetime.getMonth(), datetime.getDate());
            // Check is system is set to use 24h time (this doesn't seem to
            // work as expected though)
            final String timeS = android.provider.Settings.System.getString(
                    getThis().getActivity().getContentResolver(), android.provider.Settings.System.TIME_12_24);
            final boolean is24h = !(timeS == null || timeS.equals("12"));

            // Update demo TextViews when the "OK" button is clicked
            ((Button) mDateTimeDialogView.findViewById(R.id.SetDateTime))
                    .setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            mDateTimePicker.clearFocus();
                            String datetimestring = "";
                            int day = mDateTimePicker.get(Calendar.DAY_OF_MONTH);
                            int month = mDateTimePicker.get(Calendar.MONTH) + 1;
                            int year = mDateTimePicker.get(Calendar.YEAR);
                            int hour = 0;
                            int min = 0;
                            int append = 0;
                            if (mDateTimePicker.is24HourView()) {
                                hour = mDateTimePicker.get(Calendar.HOUR_OF_DAY);
                                min = mDateTimePicker.get(Calendar.MINUTE);
                            } else {
                                hour = mDateTimePicker.get(Calendar.HOUR);
                                min = mDateTimePicker.get(Calendar.MINUTE);
                                if (mDateTimePicker.get(Calendar.AM_PM) == Calendar.AM) {
                                    append = 1;
                                } else {
                                    append = 2;
                                }
                            }
                            if (day < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += (day + ".");
                            if (month < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += (month + "." + year + " ");
                            if (hour < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += (hour + ":");
                            if (min < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += min;

                            switch (append) {
                            case 1:
                                datetimestring += " AM";
                                break;
                            case 2:
                                datetimestring += " PM";
                                break;
                            }

                            TextView time = (TextView) result.findViewById(R.id.time);
                            time.setText(datetimestring);
                            mDateTimeDialog.dismiss();
                        }
                    });
            // Cancel the dialog when the "Cancel" button is clicked
            ((Button) mDateTimeDialogView.findViewById(R.id.CancelDialog))
                    .setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimeDialog.cancel();
                        }
                    });

            // Reset Date and Time pickers when the "Reset" button is
            // clicked
            ((Button) mDateTimeDialogView.findViewById(R.id.ResetDateTime))
                    .setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimePicker.reset();
                        }
                    });

            // Setup TimePicker
            mDateTimePicker.setIs24HourView(is24h);
            // No title on the dialog window
            mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            // Set the dialog content view
            mDateTimeDialog.setContentView(mDateTimeDialogView);
            // Display the dialog
            mDateTimeDialog.show();
        }

    });
    from = (AutoCompleteTextView) result.findViewById(R.id.from_text);
    to = (AutoCompleteTextView) result.findViewById(R.id.to_text);

    from.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            InputMethodManager mgr = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            mgr.hideSoftInputFromWindow(from.getWindowToken(), 0);
        }
    });

    to.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            InputMethodManager mgr = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            mgr.hideSoftInputFromWindow(to.getWindowToken(), 0);
        }
    });

    LocationManager locman = (LocationManager) this.getActivity().getSystemService(Context.LOCATION_SERVICE);
    Location lastloc = locman.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (MySQLiteDBAdapter.exists(this.getActivity())) {
        if (lastloc == null) {
            lastloc = locman.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }
        if (lastloc != null) {
            try {
                Palina palina = PalinaList.getPalinaGPS(lastloc);
                if (palina != null) {
                    from.setHint(palina.toString());
                }
            } catch (Exception e) {
                Log.e("HomeActivity", "Fehler bei der Location", e);
            }
        } else {
            Log.v("HomeActivity", "No location found!!");
        }
        Vector<DBObject> palinalist = PalinaList.getNameList();
        MyAutocompleteAdapter adapterfrom = new MyAutocompleteAdapter(this.getActivity(),
                android.R.layout.simple_list_item_1, palinalist);
        MyAutocompleteAdapter adapterto = new MyAutocompleteAdapter(this.getActivity(),
                android.R.layout.simple_list_item_1, palinalist);

        from.setAdapter(adapterfrom);
        to.setAdapter(adapterto);
        InputMethodManager mgr = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.hideSoftInputFromWindow(from.getWindowToken(), 0);
        mgr.hideSoftInputFromWindow(to.getWindowToken(), 0);
    }
    Button favorites = (Button) result.findViewById(R.id.favorites);
    favorites.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SelectFavoritenDialog dialog = new SelectFavoritenDialog(getThis());
            dialog.show();
        }
    });

    Button mappicker = (Button) result.findViewById(R.id.map);
    mappicker.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), MapSelectActivity.class);
            startActivityForResult(intent, REQUESTCODE_ACTIVITY);
        }
    });
    return result;
}