I have been trying to change my ImageButton source OnClick and change it back after 500 miliseconds. This is the code (There are more ImageButtons, this is just the complete example of one of the ImageButtons): [UPDATED]
package com.example.apptest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.ImageButton;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.mainactivitylayout);
ImageButton Next=(ImageButton)findViewById(R.id.nexticon);
// Here there are more buttons //
Next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent splash = new Intent(MainActivity.this, NextActivity.class);
startActivity(splash);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
ImageButton.setImageResource(R.mipmap.imgbtnonclick);
Handler h =new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
findViewById(R.id.nexticon);
ImageButton.setImageResource(R.mipmap.imgbtn);
}
}, 500);
}
});
}
It doesn't work, the message grade build says:[UPDATED]
Error:(34, 28) error: non-static method setImageResource(int) cannot be referenced from a static context
Error:(40, 36) error: non-static method setImageResource(int) cannot be referenced from a static context
Hope you can help me. Thanks!