I have a problem that when I click on the image, the first time nothing happens, only after the first click that the simple click function works and long click.
XML Code:
<ImageView
android:id="@+id/idimagem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="clickimagem"
android:src="@drawable/imagem" />
JAVA Code:
public class MainActivity extends Activity {
ImageView idimagem;
[.....]
public void clickimagem(View v) {
idimagem= (ImageView) findViewById(R.id.idimagem);
idimagem.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Click! ", Toast.LENGTH_SHORT).show();
idimagem.setOnLongClickListener(new View.OnLongClickListener() {
@Override public boolean onLongClick(View v) {
Toast.makeText(getApplicationContext(), "LongClick! ", Toast.LENGTH_SHORT).show();
return true;
}
});
}
I need to make it work right first time, not after clicking.