onclick eddittextで音を出したい。しかし、私はシングルクリックedittextで音を出す問題に直面している。 2回目以降のクリックで作業しています。そして私はedittextからフォーカスを削除したくない。私を助けてください。ここでクリックして音を鳴らす方法edittext
<LinearLayout
android:id="@+id/res3"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_mail"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/mail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="20sp"
android:maxLength="50"
android:inputType="textEmailAddress"
android:hint="@string/mailid" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
は私のJavaコードが
emailid.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
playSound("click.mp3");
return false;
}
});
public void playSound(final String p_fileName)
{
try
{
if (m_player != null && m_player.isPlaying())
{
m_player.stop();
m_player.release();
m_player = null;
}
else
{
m_player.release();
}
m_player = new MediaPlayer();
m_player.reset();
AssetFileDescriptor m_descriptor = getAssets().openFd(p_fileName);
m_player.setDataSource(m_descriptor.getFileDescriptor(), m_descriptor.getStartOffset(), m_descriptor.getLength());
m_descriptor.close();
m_player.prepare();
m_player.setVolume(1f, 1f);
m_player.setLooping(false);
m_player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
}
});
m_player.start();
}
catch (Exception e)
{
e.printStackTrace();
}
}
edittextでandroid:focusable = "false"を使用します。 –
フォーカスを削除すると、android.support.design.widget.TextInputLayoutエフェクトが機能しません。ですから、私はedittextからフォーカスを削除したくありません。 –
私もonTouchListenerを使ってみましたが、使用しません –