0
I am with a problem that when I click on the image, the first time nothing happens, only after the first click it works simple click function 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 away, not after I have to click.
It didn’t work, the application crash when starting. Probably because I added this on onCreate
– Deodoro Júnior