Example usage for android.app Dialog findViewById

List of usage examples for android.app Dialog findViewById

Introduction

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

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID or null if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via #show() or #create() ).

Usage

From source file:fr.cph.stock.android.activity.OverallActivity.java

private void showPanelUpdateHistory() {
    final Dialog alert = new Dialog(this);
    alert.setTitle("Update history");
    alert.setContentView(R.layout.history_dialog);

    final Spinner checked = (Spinner) alert.findViewById(R.id.accountList);
    List<String> list = new ArrayList<String>();
    for (Account acc : portfolio.getAccounts()) {
        list.add(acc.getName());//from   www. j a v  a 2 s  .co m
    }
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    checked.setAdapter(dataAdapter);

    Button dialogButton = (Button) alert.findViewById(R.id.dialogButtonOK);
    dialogButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            refreshItem.setActionView(R.layout.progressbar);
            refreshItem.expandActionView();
            Account account = portfolio.getAccounts().get(checked.getSelectedItemPosition());
            EditText liquidityView = (EditText) alert.findViewById(R.id.liquidityMov);
            EditText yieldView = (EditText) alert.findViewById(R.id.yield);
            EditText buyView = (EditText) alert.findViewById(R.id.buy);
            EditText sellView = (EditText) alert.findViewById(R.id.sell);
            EditText taxeView = (EditText) alert.findViewById(R.id.taxe);
            EditText commentaryView = (EditText) alert.findViewById(R.id.commentaryEditText);

            String params = null;
            params = "?accountId=" + account.getId() + "&liquidity=" + liquidityView.getText() + "&yield="
                    + yieldView.getText() + "&buy=" + buyView.getText() + "&sell=" + sellView.getText()
                    + "&taxe=" + taxeView.getText() + "&commentary="
                    + commentaryView.getText().toString().replaceAll(" ", "%20");
            MainTask mainTask = new MainTask(OverallActivity.this, UrlType.UPDATEHISTORY, params);
            mainTask.execute((Void) null);
            alert.dismiss();
        }
    });
    dialogButton = (Button) alert.findViewById(R.id.dialogButtonCancel);
    dialogButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            alert.dismiss();
        }
    });
    alert.show();
}

From source file:com.simplealertdialog.test.SupportActivityTest.java

public void testItems() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override//from   w  w  w .j  a va2s.co  m
        public void run() {
            activity.findViewById(R.id.btn_items).performClick();
            activity.getSupportFragmentManager().executePendingTransactions();
        }
    });
    getInstrumentation().waitForIdleSync();
    Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
    assertNotNull(f);

    Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
    assertNotNull(d);
    final ListView lv = (ListView) d.findViewById(R.id.list);
    assertNotNull(lv);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            lv.performItemClick(lv, 0, 0);
        }
    });
    getInstrumentation().waitForIdleSync();
}

From source file:com.simplealertdialog.test.SupportActivityTest.java

public void testItemsWithIcons() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override//from w  w  w .ja v a2  s  . co m
        public void run() {
            activity.findViewById(R.id.btn_icon_items).performClick();
            activity.getSupportFragmentManager().executePendingTransactions();
        }
    });
    getInstrumentation().waitForIdleSync();
    Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
    assertNotNull(f);

    Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
    assertNotNull(d);
    final ListView lv = (ListView) d.findViewById(R.id.list);
    assertNotNull(lv);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            lv.performItemClick(lv, 0, 0);
        }
    });
    getInstrumentation().waitForIdleSync();
}

From source file:com.simplealertdialog.test.SupportActivityTest.java

public void testSingleChoiceItems() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override//from   w ww  .  j  a  v  a 2  s  . com
        public void run() {
            activity.findViewById(R.id.btn_single_choice_list).performClick();
            activity.getSupportFragmentManager().executePendingTransactions();
        }
    });
    getInstrumentation().waitForIdleSync();
    Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
    assertNotNull(f);

    Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
    assertNotNull(d);
    final ListView lv = (ListView) d.findViewById(R.id.list);
    assertNotNull(lv);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            lv.performItemClick(lv, 0, 0);
        }
    });
    getInstrumentation().waitForIdleSync();
}

From source file:com.simplealertdialog.test.SupportActivityTest.java

public void testAdapter() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override/*from w  ww .jav  a  2 s  .  c om*/
        public void run() {
            activity.findViewById(com.simplealertdialog.test.R.id.btn_adapter).performClick();
            activity.getSupportFragmentManager().executePendingTransactions();
        }
    });
    getInstrumentation().waitForIdleSync();
    Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
    assertNotNull(f);
    Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
    assertNotNull(d);

    final ListView lv = (ListView) d.findViewById(R.id.list);
    assertNotNull(lv);
    assertTrue(lv.getAdapter() instanceof SweetsAdapter);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            lv.performItemClick(lv, 0, 0);
        }
    });
    getInstrumentation().waitForIdleSync();
}

From source file:com.simplealertdialog.test.SupportActivityTest.java

public void test3Buttons() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override//  w  w w. j  ava 2s  .  c  om
        public void run() {
            activity.findViewById(R.id.btn_3_buttons).performClick();
            activity.getSupportFragmentManager().executePendingTransactions();
        }
    });
    getInstrumentation().waitForIdleSync();
    Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
    assertNotNull(f);
    Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
    assertNotNull(d);
    View positive = d.findViewById(R.id.button_positive);
    assertNotNull(positive);
    final View negative = d.findViewById(R.id.button_negative);
    assertNotNull(negative);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            negative.performClick();
        }
    });

    getInstrumentation().waitForIdleSync();
    runTestOnUiThread(new Runnable() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public void run() {
            activity.findViewById(R.id.btn_3_buttons).performClick();
            activity.getSupportFragmentManager().executePendingTransactions();
        }
    });
    getInstrumentation().waitForIdleSync();
    f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
    assertNotNull(f);
    d = ((SimpleAlertDialogSupportFragment) f).getDialog();
    assertNotNull(d);
    final View neutral = d.findViewById(R.id.button_neutral);
    assertNotNull(neutral);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            neutral.performClick();
        }
    });
    getInstrumentation().waitForIdleSync();
}

From source file:com.facebook.samples.sessionlogin.LoginUsingActivityActivity.java

public void showDialog() {
    final Dialog dialog = new Dialog(LoginUsingActivityActivity.this);
    dialog.setContentView(R.layout.list_view_contact);
    dialog.setTitle("Pic Number");
    ListView listView = (ListView) dialog.findViewById(R.id.lc_contacts);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.spinner_row_view,
            list);/*from   w  ww .j a v a2 s.co  m*/
    listView.setAdapter(adapter);

    dialog.show();
    /*DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
            
    dialog.getWindow().setLayout(metrics.heightPixels, metrics.widthPixels);*/
}

From source file:com.simplealertdialog.test.FragmentSupportActivityTest.java

public void testButtons() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override/*from   www. j  a  va2s .c o m*/
        public void run() {
            Fragment f = activity.getSupportFragmentManager().findFragmentById(R.id.fragment_sample);
            assertNotNull(f);
            assertNotNull(f.getView());
            f.getView().findViewById(R.id.btn_frag_buttons).performClick();
            activity.getFragmentManager().executePendingTransactions();
        }
    });
    getInstrumentation().waitForIdleSync();
    Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
    assertNotNull(f);
    Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
    assertNotNull(d);
    View positive = d.findViewById(R.id.button_positive);
    assertNotNull(positive);
    final View negative = d.findViewById(R.id.button_negative);
    assertNotNull(negative);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            negative.performClick();
        }
    });
}

From source file:com.simplealertdialog.test.FragmentSupportActivityTest.java

public void test3Buttons() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override//w  w w.  ja  v a 2  s  .com
        public void run() {
            Fragment f = activity.getSupportFragmentManager().findFragmentById(R.id.fragment_sample);
            assertNotNull(f);
            assertNotNull(f.getView());
            f.getView().findViewById(R.id.btn_frag_3_buttons).performClick();
            activity.getFragmentManager().executePendingTransactions();
        }
    });
    getInstrumentation().waitForIdleSync();
    Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
    assertNotNull(f);
    Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
    assertNotNull(d);
    View positive = d.findViewById(R.id.button_positive);
    assertNotNull(positive);
    final View negative = d.findViewById(R.id.button_negative);
    assertNotNull(negative);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            negative.performClick();
        }
    });
}

From source file:com.simplealertdialog.test.FragmentSupportActivityTest.java

public void testMessage() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override//from www.  ja v a 2 s. c om
        public void run() {
            Fragment f = activity.getSupportFragmentManager().findFragmentById(R.id.fragment_sample);
            assertNotNull(f);
            assertNotNull(f.getView());
            f.getView().findViewById(R.id.btn_frag_message).performClick();
            activity.getFragmentManager().executePendingTransactions();
        }
    });
    getInstrumentation().waitForIdleSync();
    Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
    assertNotNull(f);
    Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
    assertNotNull(d);
    final View positive = d.findViewById(R.id.button_positive);
    assertNotNull(positive);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            positive.performClick();
        }
    });
}