Code example for TextSwitcher

Methods: getCurrentView, setText

0
        addButton.setOnClickListener(new OnClickListener() {
            @Override 
            public void onClick(View view) {
                Log.d(LOG_TAG, "Adding number of items, for item: " + itemName);
                TextSwitcher itemCount = (TextSwitcher) findViewById(textViewId);
                int updatedValue = Integer.parseInt(((TextView) itemCount.getCurrentView()).getText().toString()) + 1;
                itemCount.setText(String.valueOf(updatedValue));
                if (updatedValue > 0) {
                    substractButton.setEnabled(true);
                } 
            } 
        }); 
    } 
 
    /** 
     * Initializes the score TextSwitcher for the specified {@code textSwitcher}. 
     */ 
    private void initializeTextSwitcher(final TextSwitcher textSwitcher) {
        textSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
            @Override 
            public View makeView() {