private void setListener() { searchEt.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { /*关闭键盘*/ inputMethodManager.hideSoftInputFromWindow( revealRootView.getApplicationWindowToken(), 0); if (TextUtils.isEmpty(searchEt.getText().toString())) return true; ProductKeyListActivity.navigateToProductKeyList( SearchActivity.this, searchEt.getText().toString(), searchEt.getText().toString()); overridePendingTransition(0, 0); return true; } return false; } }); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); myOnAttach(getActivity()); final StudentsAdapter studentsAdapter = new StudentsAdapter(students, getActivity()); RecyclerView recyclerView = (RecyclerView) getActivity().findViewById(R.id.recyclerView); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity()); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(studentsAdapter); getActivity().findViewById(R.id.progressBar).setVisibility(View.GONE); getActivity().findViewById(R.id.no_result).setVisibility(View.GONE); getActivity().findViewById(R.id.recyclerView).setVisibility(View.VISIBLE); final AppCompatEditText skillsEdit = (AppCompatEditText) getActivity().findViewById(R.id.skills); skillsEdit.setImeOptions(EditorInfo.IME_ACTION_DONE); getActivity() .findViewById(R.id.searchButton) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String text = skillsEdit.getText().toString().trim(); ArrayList<String> words = getWordsFromText(text); hideSoftKeyboard(); getActivity().findViewById(R.id.progressBar).setVisibility(View.VISIBLE); getActivity().findViewById(R.id.no_result).setVisibility(View.GONE); getActivity().findViewById(R.id.recyclerView).setVisibility(View.GONE); User.searchStudentsBySkills( getActivity(), words, new User.OnUsersDownloadedCallback() { @Override public void onUsersDownloaded(List<User> users) { getActivity().findViewById(R.id.progressBar).setVisibility(View.GONE); if (users == null || users.size() == 0) { getActivity().findViewById(R.id.no_result).setVisibility(View.VISIBLE); } else { getActivity().findViewById(R.id.recyclerView).setVisibility(View.VISIBLE); students.clear(); students.addAll(users); sortUsers(); studentsAdapter.setUsers(students); studentsAdapter.notifyDataSetChanged(); } } }); } }); skillsEdit.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boolean handled = false; if (actionId == EditorInfo.IME_ACTION_DONE) { getActivity().findViewById(R.id.searchButton).performClick(); handled = true; } return handled; } }); }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Bundle bundle = getArguments(); final Alarm alarm = bundle.getParcelable(KEY_ALARM); final TimerObj timer = bundle.getParcelable(KEY_TIMER); final String tag = bundle.getString(KEY_TAG); final String label = savedInstanceState != null ? savedInstanceState.getString(KEY_LABEL) : bundle.getString(KEY_LABEL); final Context context = getActivity(); final int colorAccent = Utils.obtainStyledColor(context, R.attr.colorAccent, Color.RED); final int colorControlNormal = Utils.obtainStyledColor(context, R.attr.colorControlNormal, Color.WHITE); mLabelBox = new AppCompatEditText(context); mLabelBox.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { set(alarm, timer, tag); return true; } return false; } }); mLabelBox.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) { final int color = TextUtils.isEmpty(s) ? colorControlNormal : colorAccent; mLabelBox.setSupportBackgroundTintList(ColorStateList.valueOf(color)); } @Override public void afterTextChanged(Editable editable) {} }); mLabelBox.setText(label); mLabelBox.selectAll(); final int padding = getResources().getDimensionPixelSize(R.dimen.label_edittext_padding); final AlertDialog alertDialog = new AlertDialog.Builder(context) .setView(mLabelBox, padding, 0, padding, 0) .setPositiveButton( R.string.time_picker_set, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { set(alarm, timer, tag); } }) .setNegativeButton( R.string.time_picker_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); } }) .setMessage(R.string.label) .create(); alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); return alertDialog; }