示例#1
1
 @SuppressLint("ValidFragment")
 public static void startFilterEntry(final Activity activity) {
   new DialogFragment() {
     public Dialog onCreateDialog(Bundle savedInstanceState) {
       final EditText filterInput = new EditText(activity);
       filterInput.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER);
       ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE))
           .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
       return new AlertDialog.Builder(activity)
           .setView(filterInput)
           .setPositiveButton(
               android.R.string.ok,
               new OnClickListener() {
                 @Override
                 public void onClick(DialogInterface dialog, int which) {
                   String filterText = filterInput.getText().toString();
                   if (activity instanceof Filterable)
                     ((Filterable) activity).filterItems(filterText);
                 }
               })
           .setNegativeButton(android.R.string.cancel, null)
           .create();
     };
   }.show(activity.getFragmentManager(), "filterentry");
 }
 /**
  * Invoke with a {@link org.junit.runner.Runner} to cause all tests it intends to run to first be
  * checked with the filter. Only those that pass the filter will be run.
  *
  * @param child the runner to be filtered by the receiver
  * @throws NoTestsRemainException if the receiver removes all tests
  */
 public void apply(Object child) throws NoTestsRemainException {
   if (!(child instanceof Filterable)) {
     return;
   }
   Filterable filterable = (Filterable) child;
   filterable.filter(this);
 }