Example usage for android.text TextWatcher TextWatcher

List of usage examples for android.text TextWatcher TextWatcher

Introduction

In this page you can find the example usage for android.text TextWatcher TextWatcher.

Prototype

TextWatcher

Source Link

Usage

From source file:com.miz.mizuu.fragments.IdentifyMovieFragment.java

public void onViewCreated(View v, Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);

    mToolbar = (Toolbar) v.findViewById(R.id.toolbar);
    ((MizActivity) getActivity()).setSupportActionBar(mToolbar);

    mListView = (ListView) v.findViewById(R.id.listView1);
    mQuery = (EditText) v.findViewById(R.id.editText1);
    mSpinner = (Spinner) v.findViewById(R.id.spinner1);
    mProgress = (ProgressBar) v.findViewById(R.id.progressBar1);

    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override//w  w w .  j  av a2 s  .co  m
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            updateMovie(arg2);
        }
    });
    mListView.setEmptyView(v.findViewById(R.id.no_results));
    v.findViewById(R.id.no_results).setVisibility(View.GONE); // Manually make it gone to begin with

    mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mLocale = mSpinnerAdapter.getItem(position).getLanguage();
            searchForMovies();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mSpinnerAdapter = new LanguageAdapter();
    mSpinner.setAdapter(mSpinnerAdapter);
    String language = PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getString(LANGUAGE_PREFERENCE, "en");
    mSpinner.setSelection(mSpinnerAdapter.getIndexForLocale(language));

    mQuery.setText(mMovieStructure.getDecryptedFilename());
    mQuery.setSelection(mQuery.length());
    mQuery.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) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.toString().length() > 0)
                searchForMovies();
            else {
                mMovieSearch.cancel(true);
                mAdapter.clearItems();
                mAdapter.notifyDataSetChanged();
            }
        }
    });
    mQuery.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN
                    || actionId == EditorInfo.IME_ACTION_SEARCH)
                searchForMovies();
            return true;
        }
    });

    if (mMovieSearch == null) {
        if (MizLib.isOnline(getActivity())) {
            mMovieSearch = new MovieSearch(getActivity(), mQuery.getText().toString());
        } else {
            Toast.makeText(getActivity(), getString(R.string.noInternet), Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:com.example.carrie.carrie_test1.druginfo.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_druginfo);
    Bundle bundle = getIntent().getExtras();
    my_id = bundle.getString("my_id");//get  id
    my_google_id = bundle.getString("my_google_id");//get google_ id
    my_mon_id = bundle.getString("my_supervise_id");
    m_calid = bundle.getString("m_calid", "not found");

    Log.d("qqqqq", m_calid);

    btmbar = (RelativeLayout) findViewById(R.id.btmbar);
    if (my_id.equals("0") && my_google_id.equals("0") && my_mon_id.equals("0")) {
        //???????
        btmbar.setVisibility(View.GONE);
    } else {//from   ww w  .  j av  a 2  s . co m
        BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavView_Bar);
        BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
        Menu menu = bottomNavigationView.getMenu();
        MenuItem menuItem = menu.getItem(3);
        menuItem.setChecked(true);

        bottomNavigationView.setOnNavigationItemSelectedListener(
                new BottomNavigationView.OnNavigationItemSelectedListener() {
                    @Override
                    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                        switch (item.getItemId()) {
                        case R.id.ic_list:
                            Intent intent0 = new Intent(druginfo.this, Choice.class);
                            Bundle bundle0 = new Bundle();
                            bundle0.putString("memberid", my_id);
                            bundle0.putString("my_google_id", my_google_id);
                            bundle0.putString("my_supervise_id", my_mon_id);
                            intent0.putExtras(bundle0); // put???
                            startActivity(intent0);
                            break;

                        case R.id.ic_eye:
                            Intent intent1 = new Intent(druginfo.this, MonitorActivity.class);
                            Bundle bundle1 = new Bundle();
                            bundle1.putString("my_id", my_id);
                            bundle1.putString("my_google_id", my_google_id);
                            bundle1.putString("my_supervise_id", my_mon_id);
                            intent1.putExtras(bundle1);
                            startActivity(intent1);
                            break;

                        case R.id.ic_home:
                            Intent intent2 = new Intent(druginfo.this, MainActivity.class);
                            Bundle bundle2 = new Bundle();
                            bundle2.putString("googleid", my_google_id);
                            intent2.putExtras(bundle2);
                            startActivity(intent2);
                            break;

                        case R.id.ic_information:
                            Intent intent3 = new Intent(druginfo.this, druginfo.class);
                            Bundle bundle3 = new Bundle();
                            bundle3.putString("my_id", my_id);
                            bundle3.putString("my_google_id", my_google_id);
                            bundle3.putString("my_supervise_id", my_mon_id);
                            intent3.putExtras(bundle3);
                            startActivity(intent3);
                            break;

                        case R.id.ic_beacon:
                            Intent intent4 = new Intent(druginfo.this, Beacon.class);
                            Bundle bundle4 = new Bundle();
                            bundle4.putString("my_id", my_id);
                            bundle4.putString("my_google_id", my_google_id);
                            bundle4.putString("my_supervise_id", my_mon_id);
                            intent4.putExtras(bundle4);
                            startActivity(intent4);
                            break;
                        }

                        return false;
                    }
                });
    }

    listView = (ListView) findViewById(R.id.listview);
    editText = (EditText) findViewById(R.id.textsearch);

    editText.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) {
            if (!s.toString().equals("")) {
                //reset listview

                //                    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
                //                    data_list = new ArrayList<>();
                //                    load_data_from_server(0);
                //
                //                    gridLayoutManager = new GridLayoutManager(getBaseContext(), 2);
                //                    recyclerView.setLayoutManager(gridLayoutManager);
                //
                //                    adapter = new CustomAdapter2(getBaseContext(), data_list);
                //                    recyclerView.setAdapter(adapter);
                //
                //                    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                //                        @Override
                //                        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                //
                //                            if (gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size() - 1) {
                //                                load_data_from_server(data_list.get(data_list.size() - 1).getId());
                //                            }
                //
                //                        }
                //                    });
                recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
                data_list2 = new ArrayList<>();
                Log.d("searchtest", "3");
                load_data_from_server_search(s.toString());

                Log.d("searchtest", "1");
                gridLayoutManager = new GridLayoutManager(getBaseContext(), 2);
                recyclerView.setLayoutManager(gridLayoutManager);
                Log.d("searchtest", "2");
                adapter = new CustomAdapter2(getBaseContext(), data_list2, m_calid);
                recyclerView.setAdapter(adapter);
            } else {
                recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

                gridLayoutManager = new GridLayoutManager(getBaseContext(), 2);
                recyclerView.setLayoutManager(gridLayoutManager);

                adapter = new CustomAdapter2(getBaseContext(), data_list, m_calid);
                recyclerView.setAdapter(adapter);

            }

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    data_list = new ArrayList<>();
    load_data_from_server(0);

    gridLayoutManager = new GridLayoutManager(this, 2);
    recyclerView.setLayoutManager(gridLayoutManager);

    adapter = new CustomAdapter2(this, data_list, m_calid);
    recyclerView.setAdapter(adapter);

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

            if (gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size() - 1) {
                load_data_from_server(data_list.get(data_list.size() - 1).getId());
            }

        }
    });

}

From source file:com.nextgis.maplibui.formcontrol.AutoTextEdit.java

@Override
public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor,
        SharedPreferences preferences) throws JSONException {
    ControlHelper.setClearAction(this);

    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    mFieldName = attributes.getString(JSON_FIELD_NAME_KEY);
    mIsShowLast = ControlHelper.isSaveLastValue(attributes);
    mAllowSaveNewValue = attributes.optBoolean(JSON_ALLOW_NEW_VALUES);

    if (!ControlHelper.isEnabled(fields, mFieldName)) {
        setEnabled(false);//from  www .j a v a  2  s .c o m
        setTextColor(Color.GRAY);
    }

    String lastValue = null;
    if (ControlHelper.hasKey(savedState, mFieldName))
        lastValue = savedState.getString(ControlHelper.getSavedStateKey(mFieldName));
    else if (null != featureCursor) {
        int column = featureCursor.getColumnIndex(mFieldName);
        if (column >= 0)
            lastValue = featureCursor.getString(column);
    } else if (mIsShowLast)
        lastValue = preferences.getString(mFieldName, null);

    mAliasValueMap = new HashMap<>();
    if (attributes.has(ConstantsUI.JSON_NGW_ID_KEY) && attributes.getLong(ConstantsUI.JSON_NGW_ID_KEY) != -1) {
        MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
        if (null == map)
            throw new IllegalArgumentException("The map should extends MapContentProviderHelper or inherited");

        String account = element.optString(SyncStateContract.Columns.ACCOUNT_NAME);
        long id = attributes.getLong(JSON_NGW_ID_KEY);
        for (int i = 0; i < map.getLayerCount(); i++) {
            if (map.getLayer(i) instanceof NGWLookupTable) {
                NGWLookupTable table = (NGWLookupTable) map.getLayer(i);
                if (table.getRemoteId() != id || !table.getAccountName().equals(account))
                    continue;

                for (Map.Entry<String, String> entry : table.getData().entrySet()) {
                    mAliasValueMap.put(entry.getValue(), entry.getKey());
                    if (entry.getKey().equals(lastValue))
                        lastValue = entry.getValue();
                }

                break;
            }
        }
    } else {
        JSONArray values = attributes.getJSONArray(JSON_VALUES_KEY);
        for (int j = 0; j < values.length(); j++) {
            JSONObject keyValue = values.getJSONObject(j);
            String value = keyValue.getString(JSON_VALUE_NAME_KEY);
            String alias = keyValue.getString(JSON_VALUE_ALIAS_KEY);
            mAliasValueMap.put(alias, value);
            if (value.equals(lastValue))
                lastValue = alias;
        }
    }

    setText(lastValue);
    mAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item,
            new ArrayList<>(mAliasValueMap.keySet()));
    setAdapter(mAdapter);

    setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus && getText().length() == 0) {
                postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        showDropDown();
                    }
                }, 100);
            }
        }
    });

    addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if (charSequence.length() < 1)
                getOnFocusChangeListener().onFocusChange(AutoTextEdit.this, true);
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });
}

From source file:com.app.blockydemo.ui.dialogs.NewVariableDialog.java

private void handleOnShow(final Dialog dialogNewVariable) {
    final Button positiveButton = ((AlertDialog) dialogNewVariable).getButton(AlertDialog.BUTTON_POSITIVE);
    positiveButton.setEnabled(false);//w w  w . j  av a 2s .c  o m

    EditText dialogEditText = (EditText) dialogNewVariable
            .findViewById(R.id.dialog_formula_editor_variable_name_edit_text);

    InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.showSoftInput(dialogEditText, InputMethodManager.SHOW_IMPLICIT);

    dialogEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable editable) {

            String variableName = editable.toString();
            if (ProjectManager.getInstance().getCurrentProject().getUserVariables()
                    .getUserVariable(variableName, ProjectManager.getInstance().getCurrentSprite()) != null) {

                Toast.makeText(getActivity(), R.string.formula_editor_existing_variable, Toast.LENGTH_SHORT)
                        .show();

                positiveButton.setEnabled(false);
            } else {
                positiveButton.setEnabled(true);
            }

            if (editable.length() == 0) {
                positiveButton.setEnabled(false);
            }
        }
    });
}

From source file:cn.ucai.yizhesale.activity.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    //T??home???appcrash
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
        return;/*from  ww w .  j  a  v  a 2  s.c om*/
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);

    //???
    blackList = EMContactManager.getInstance().getBlackListUsernames();
    contactList = new ArrayList<EMUser>();
    // ?contactlist
    getContactList();

    //?
    query = (EditText) getView().findViewById(R.id.query);
    query.setHint(R.string.search);
    clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s);
            if (s.length() > 0) {
                clearSearch.setVisibility(View.VISIBLE);
            } else {
                clearSearch.setVisibility(View.INVISIBLE);

            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void afterTextChanged(Editable s) {
        }
    });
    clearSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            query.getText().clear();
            hideSoftKeyboard();
        }
    });

    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                EMUser user = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList()
                        .get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class));
            } else {
                // demo??
                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId",
                        adapter.getItem(position).getUsername()));
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact);
    // ?
    addContactView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), AddContactActivity.class));
        }
    });
    registerForContextMenu(listView);

    progressBar = (View) getView().findViewById(R.id.progress_bar);

    contactSyncListener = new HXContactSyncListener();
    HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener);

    blackListSyncListener = new HXBlackListSyncListener();
    HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener);

    contactInfoSyncListener = new HXContactInfoSyncListener();
    ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager()
            .addSyncContactInfoListener(contactInfoSyncListener);

    if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) {
        progressBar.setVisibility(View.VISIBLE);
    } else {
        progressBar.setVisibility(View.GONE);
    }
}

From source file:cmu.cconfs.instantMessage.activities.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    //T??home???appcrash
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
        return;/*from  w  w  w  .j a  v a  2s .  co m*/
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);

    //???
    blackList = EMContactManager.getInstance().getBlackListUsernames();
    contactList = new ArrayList<User>();
    // ?contactlist
    getContactList();

    //?
    query = (EditText) getView().findViewById(R.id.query);
    query.setHint(R.string.search);
    clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s);
            if (s.length() > 0) {
                clearSearch.setVisibility(View.VISIBLE);
            } else {
                clearSearch.setVisibility(View.INVISIBLE);

            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void afterTextChanged(Editable s) {
        }
    });
    clearSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            query.getText().clear();
            hideSoftKeyboard();
        }
    });

    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                User user = ((IMHXSDKHelper) HXSDKHelper.getInstance()).getContactList()
                        .get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), GroupsActivity.class));
            } else if (Constant.CHAT_ROOM.equals(username)) {
                //??
                startActivity(new Intent(getActivity(), PublicChatRoomsActivity.class));
            } else if (Constant.CHAT_ROBOT.equals(username)) {
                //Robot?
                startActivity(new Intent(getActivity(), RobotsActivity.class));
            } else {
                // demo??
                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId",
                        adapter.getItem(position).getUsername()));
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact);
    // ?
    addContactView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), AddContactActivity.class));
        }
    });
    registerForContextMenu(listView);

    progressBar = (View) getView().findViewById(R.id.progress_bar);

    contactSyncListener = new HXContactSyncListener();
    HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener);

    blackListSyncListener = new HXBlackListSyncListener();
    HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener);

    contactInfoSyncListener = new HXContactInfoSyncListener();
    ((IMHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager()
            .addSyncContactInfoListener(contactInfoSyncListener);

    if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) {
        progressBar.setVisibility(View.VISIBLE);
    } else {
        progressBar.setVisibility(View.GONE);
    }
}

From source file:com.miz.mizuu.fragments.IdentifyTvShowEpisodeFragment.java

public void onViewCreated(View v, Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);

    mToolbar = (Toolbar) v.findViewById(R.id.toolbar);
    ((MizActivity) getActivity()).setSupportActionBar(mToolbar);

    mListView = (ListView) v.findViewById(R.id.listView1);
    mQuery = (EditText) v.findViewById(R.id.editText1);
    mSpinner = (Spinner) v.findViewById(R.id.spinner1);
    mProgress = (ProgressBar) v.findViewById(R.id.progressBar1);

    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override/*from w  w w.  ja v  a 2 s  .  com*/
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            updateShow(arg2);
        }
    });
    mListView.setEmptyView(v.findViewById(R.id.no_results));
    v.findViewById(R.id.no_results).setVisibility(View.GONE); // Manually make it gone to begin with

    mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mLocale = mSpinnerAdapter.getItem(position).getLanguage();
            searchForShows();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mSpinnerAdapter = new LanguageAdapter();
    mSpinner.setAdapter(mSpinnerAdapter);
    String language = PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getString(LANGUAGE_PREFERENCE, "en");
    mSpinner.setSelection(mSpinnerAdapter.getIndexForLocale(language));

    mQuery.setText(mShowTitle);
    mQuery.setSelection(mQuery.length());
    mQuery.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) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.toString().length() > 0)
                searchForShows();
            else {
                mTvShowSearch.cancel(true);
                mAdapter.clearItems();
                mAdapter.notifyDataSetChanged();
            }
        }
    });
    mQuery.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN
                    || actionId == EditorInfo.IME_ACTION_SEARCH)
                searchForShows();
            return true;
        }
    });

    if (mTvShowSearch == null) {
        if (MizLib.isOnline(getActivity())) {
            mTvShowSearch = new TvShowSearch(getActivity(), mQuery.getText().toString());
        } else {
            Toast.makeText(getActivity(), getString(R.string.noInternet), Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:com.easemob.chatui.activity.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    //T??home???appcrash
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
        return;/*from w  w  w.java2  s. c  o m*/
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);

    //???
    blackList = EMContactManager.getInstance().getBlackListUsernames();
    contactList = new ArrayList<User>();
    // ?contactlist
    getContactList();

    //?
    query = (EditText) getView().findViewById(R.id.query);
    query.setHint(R.string.search);
    clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s);
            if (s.length() > 0) {
                clearSearch.setVisibility(View.VISIBLE);
            } else {
                clearSearch.setVisibility(View.INVISIBLE);

            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void afterTextChanged(Editable s) {
        }
    });
    clearSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            query.getText().clear();
            hideSoftKeyboard();
        }
    });

    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                /** ?*/
                User user = BeewayApplication.getInstance().getContactList().get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(
                        new Intent(getActivity(), com.easemob.chatui.activity.NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                /** ?*/
                startActivity(new Intent(getActivity(), com.easemob.chatui.activity.GroupsActivity.class));
            } else {
                /** */
                startActivity(new Intent(getActivity(), UserDetailsActivity.class).putExtra("friendid",
                        adapter.getItem(position).getUsername()));
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    registerForContextMenu(listView);

    progressBar = (View) getView().findViewById(R.id.progress_bar);

    contactSyncListener = new HXContactSyncListener();
    //contactSyncListener.onSyncSucess(true);
    HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener);

    blackListSyncListener = new HXBlackListSyncListener();
    HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener);

    if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) {
        progressBar.setVisibility(View.VISIBLE);
    } else {
        progressBar.setVisibility(View.GONE);
    }
}

From source file:com.example.android.viewpager.MondayFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_monday, container, false);

    String[] arrayNorm = { "??", "??", "??",
            "??", "??", "???", "??",
            "??", "?", "??", "?",
            "?", "??", "?", "?",
            "?", "??", "??",
            "?", "?", "?",
            "?", "", "?", "", "",
            "?", "?", "??",
            "??", "??", "?", "",
            "?", "?", "?", "?",
            "?", "", "?", "?",
            "??", "??", "?",
            "?", "?", "?", "",
            "", "?", "?", "?",
            "??", "??", "", "?",
            "??", "?", "?", "?",
            "??", "?", "?", "?",
            "", "?", "", "?",
            "?", "?", "?", "?",
            "?", "", "", "?",
            "?", "?", "", "?",
            "?", "", "?", "?",
            "?", "?", "??", "?",
            "?", "?" };

    final String[] arraySokr = { "az", "sq", "am", "en", "ar", "hy", "af", "eu", "ba", "be", "bn", "bg", "bs",
            "cy", "hu", "vi", "ht", "gl", "nl", "mrj", "el", "ka", "gu", "da", "he", "yi", "id", "ga", "it",
            "is", "es", "kk", "kn", "ca", "ky", "zh", "ko", "xh", "la", "lv", "lt", "lb", "mg", "ms", "ml",
            "mt", "mk", "mi", "mr", "mhr", "mn", "de", "ne", "no", "pa", "pap", "fa", "pl", "pt", "ro", "ru",
            "ceb", "sr", "si", "sk", "sl", "sw", "su", "tg", "th", "tl", "ta", "tt", "te", "tr", "udm", "uz",
            "uk", "ur", "fi", "fr", "hi", "hr", "cs", "sv", "gd", "et", "eo", "jv", "ja" };

    spinner = (Spinner) view.findViewById(R.id.spinner_nav);
    spinner2 = (Spinner) view.findViewById(R.id.spinner_nav2);
    translatedTextTextView = (TextView) view.findViewById(R.id.textView);
    textToTranslateEditText = (EditText) view.findViewById(R.id.editText2);

    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(),
            android.R.layout.simple_spinner_item, arrayNorm); //selected item will look like a spinner set from XML
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(spinnerArrayAdapter);
    spinner2.setAdapter(spinnerArrayAdapter);

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View itemSelected, int selectedItemPosition,
                long selectedId) {
            int posNum = spinner.getSelectedItemPosition();
            l1 = arraySokr[posNum];/*from  w ww  .  j a  va 2s  . co m*/
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View itemSelected, int selectedItemPosition,
                long selectedId) {

            int posNum = spinner.getSelectedItemPosition();
            l2 = arraySokr[posNum];
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    textToTranslateEditText.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) {
            //? ,    ?
            if (textToTranslateEditText.getText().toString().isEmpty()) {
                Toast.makeText(getActivity().getApplicationContext(),
                        " ? ? ", Toast.LENGTH_SHORT).show();
            } else {
                if (textToTranslateEditText.isFocused()) {
                    String text = textToTranslateEditText.getText().toString();

                    String language = l1 + "-" + l2;
                    new Task().execute(text, language);

                }
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
            //TranslateWord translateWord = new TranslateWord(textToTranslateEditText.getText().toString(),translatedTextTextView.getText().toString(), R.drawable.off_fav, "en-ru");
            //myRef.push().setValue(translateWord);
        }
    });

    return view;

}

From source file:com.aibasis.parent.ui.chat.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    //T??home???appcrash
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
        return;// w ww.  j  a  v a  2 s  .c  o m
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);

    //???
    blackList = EMContactManager.getInstance().getBlackListUsernames();
    contactList = new ArrayList<User>();
    // ?contactlist
    getContactList();

    //?
    query = (EditText) getView().findViewById(R.id.query);
    query.setHint(R.string.search);
    clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s);
            if (s.length() > 0) {
                clearSearch.setVisibility(View.VISIBLE);
            } else {
                clearSearch.setVisibility(View.INVISIBLE);

            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void afterTextChanged(Editable s) {
        }
    });
    clearSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            query.getText().clear();
            hideSoftKeyboard();
        }
    });

    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                User user = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList()
                        .get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), GroupsActivity.class));
            } else if (Constant.CHAT_ROOM.equals(username)) {
                //??
                startActivity(new Intent(getActivity(), PublicChatRoomsActivity.class));
            } else if (Constant.CHAT_ROBOT.equals(username)) {
                //Robot?
                startActivity(new Intent(getActivity(), RobotsActivity.class));
            } else {
                // demo??
                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId",
                        adapter.getItem(position).getUsername()));
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    //ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact);
    // ?
    //      addContactView.setOnClickListener(new OnClickListener() {
    //
    //         @Override
    //         public void onClick(View v) {
    //            startActivity(new Intent(getActivity(), AddContactActivity.class));
    //         }
    //      });
    registerForContextMenu(listView);

    progressBar = (View) getView().findViewById(R.id.progress_bar);

    contactSyncListener = new HXContactSyncListener();
    HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener);

    blackListSyncListener = new HXBlackListSyncListener();
    HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener);

    contactInfoSyncListener = new HXContactInfoSyncListener();
    ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager()
            .addSyncContactInfoListener(contactInfoSyncListener);

    if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) {
        progressBar.setVisibility(View.VISIBLE);
    } else {
        progressBar.setVisibility(View.GONE);
    }
}