2013-12-08 1 views
0
Button buttonClear; 
private TextView inputValue; 
private static final String DIGITS = "."; 
private Boolean userIsInTheMiddleOfTypingANumber = false; 

вот некоторая анимацияВ приложении клавиатура "Число" с 2 TextView

TextView image1; 
TextView image2; 
TextView image3; 
TextView image4; 
TextView image5; 

    @Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 


    inputValue = (TextView) findViewById(R.id.ePrice); 
    findViewById(R.id.button0).setOnClickListener(this); 
    findViewById(R.id.button1).setOnClickListener(this); 
    findViewById(R.id.button2).setOnClickListener(this); 
    findViewById(R.id.button3).setOnClickListener(this); 
    findViewById(R.id.button4).setOnClickListener(this); 
    findViewById(R.id.button5).setOnClickListener(this); 
    findViewById(R.id.button6).setOnClickListener(this); 
    findViewById(R.id.button7).setOnClickListener(this); 
    findViewById(R.id.button8).setOnClickListener(this); 
    findViewById(R.id.button9).setOnClickListener(this); 
    findViewById(R.id.buttonDecimalPoint).setOnClickListener(this); 

    Button buttonClear = (Button) findViewById(R.id.buttonClear); 

    /** Backspace for in app keyboard */ 
    buttonClear.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      inputValue.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, 
        KeyEvent.KEYCODE_DEL)); 
     } 
    }); 
    /** Backspace */ 

    /** Disable Key API level 11 where suppose to disable the android keybaord i also tried to change the manifest but the keyboard still coming up */ 
    inputValue.setInputType(InputType.TYPE_NULL); 
    if (android.os.Build.VERSION.SDK_INT >= 11) { 
     inputValue.setRawInputType(InputType.TYPE_CLASS_TEXT); 
     inputValue.setTextIsSelectable(true); 
    } 

     image1 = (TextView)findViewById(R.id.tPercent); 
     image2 = (TextView)findViewById(R.id.textPercent); 
     image3 = (TextView)findViewById(R.id.Percent_10); 
     image4 = (TextView)findViewById(R.id.Percent_pay); 

     image5 = (TextView)findViewById(R.id.ePrice); 

     Animation animationFadeIn1 = AnimationUtils.loadAnimation(this, R.anim.fadein_1); 
     image1.startAnimation(animationFadeIn1); 
     Animation animationFadeIn2 = AnimationUtils.loadAnimation(this, R.anim.fadein_2); 
     image2.startAnimation(animationFadeIn2); 
     Animation animationFadeIn3 = AnimationUtils.loadAnimation(this, R.anim.fadein_3); 
     image3.startAnimation(animationFadeIn3); 
     Animation animationFadeIn4 = AnimationUtils.loadAnimation(this, R.anim.fadein_4); 
     image4.startAnimation(animationFadeIn4); 

     Animation animationFadeIn5 = AnimationUtils.loadAnimation(this, R.anim.shake); 
     image5.startAnimation(animationFadeIn5); 


    // here is first EditText which i can type normally which in app keyboard 
    final EditText editPrice = (EditText) findViewById(R.id.ePercents); 
    // here is second EditText where i can't type anything with in app keyboard 
    final EditText ePercent = (EditText) findViewById(R.id.ePrice); 
    // to get the 1 result 
    final TextView result = (TextView) findViewById(R.id.viewResult); 
    // to get the 2 result 
    final TextView result2 = (TextView) findViewById(R.id.viewResultPay); 

    Button buttonConvert = (Button) findViewById(R.id.buttonConvert); 
    buttonConvert.setOnClickListener(new OnClickListener() { 

    /**Here is some calculation happening **/ 

} 

/**here is the onclick for buttons for in app keyboard**/ 

    public void onClick(View v) { 
    /** Numbers */ 
    String buttonPressed = ((Button) v).getText().toString(); 
    if (DIGITS.contains(buttonPressed)) { 
     // digit was pressed 
     if (userIsInTheMiddleOfTypingANumber) { 

      if (buttonPressed.equals(".") 
        && inputValue.getText().toString().contains(".")) { 
      } else { 
       inputValue.append(buttonPressed); 
      } 

     } else { 

      if (buttonPressed.equals(".")) { 
       inputValue.setText(0 + buttonPressed); 
      } else { 
       inputValue.setText(buttonPressed); 
      } 

      userIsInTheMiddleOfTypingANumber = true; 
     } 
    } 
    /** Numbers */ 

} 

Что я хочу:

  1. Чтобы отключить андроид клавиатуры.

  2. Мне нужно ввести EditText с моими числовыми кнопками в каждом файле EditText .. есть 2 EditText.

Я пытался дублировать OnClick для цифр, но его письма в то же время в обоих EditText-х

Цените любую помощь.

ответ

0

1/Для отключения клавиатуры Android, сделать класс, расширяющий EditText, и применить ее к своему edittexts

editPrice.setInputType(InputType.TYPE_NULL); 

2/Для добавления номера к вашему EditText

// On click on a digit button 
editPrice.setText(editPrice.getText().toString().concat(String.valueOf(yourNumber))); 

// For removing last char (in case of a delete button) 
editPrice.setText(editPrice.getText().toString().substring(0, editPrice.getText().toString().length()-1)); 
+0

Я не хочу используйте конкретные номера ... у меня есть клавиатура с самодельными номерами. – user3051834

+0

Я хочу набрать числа в первом edittext, а затем во втором, а затем вычислить эти числа, чтобы получить результат. и я хочу сделать это с моей клавиатурой, а не с клавиатурой Android. – user3051834

Смежные вопросы