2012-05-10 41 views
2

4つのテキストボックスがあり、ユーザーがボタンをクリックすると、関連するテキストを挿入して次のテキストボックスに移動し、そのボックスに次のテキストを挿入します。私はこれまでのところ私のコードを少し距離を持っています。Androidで現在フォーカスのあるテキストボックスにテキストを挿入する方法

Time1Btn = (Button)findViewById(R.id.Time1Btn); 
Time2Btn = (Button)findViewById(R.id.Time2Btn); 
Time1HrEB = (EditText)findViewById(R.id.Time1HrEB); // i would guess this would be replaced 

Time1Btn.setOnClickListener(MyOnClickListener); 
Time2Btn.setOnClickListener(MyOnClickListener); 

private View.OnClickListener MyOnClickListener = new OnClickListener(){ 
    public void onClick(View v){ 
    Button b = (Button)v; 
    EditText e = (EditText).getCurrentFocus(); // attemt of what to do 

    String buttonText = b.getText().toString(); 
    e.setText(buttonText); // this is the line i wish to replace. 
    int id = getCurrentFocus().getNextFocusRightId(); 

     findViewById(id).requestFocus(); 
     } 
}; 

私のレイアウトファイルはです。

<EditText 
      android:id="@+id/Time1HrEB" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="number" 
      android:maxWidth="30dp" 
      android:minWidth="30dp" 
      android:nextFocusRight="@+id/Time2HrEB" 
      > 
</EditText> 

<EditText 
      android:id="@+id/Time2HrEB" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="number" 
      android:minWidth="30dp" 
      /> 
etc... 

任意のアイデア...私はあなたが

View et = getCurrentFocus() 
EditText e = (EditText) et; 
e.setText(buttonText); 

はそれを試してみると、私に知らせて接近している...

答えて

3

をいくつかのことをしようと試みてきました。

関連する問題