Android imageButton onClick method doesn't call

EDIT: posting full code (other than XML, as that is a bunch of ridiculous table formatting!) Please ignore the code that doesn't apply to my question! I'm just getting functionality right now. I will fix it later.

Hey guys! The first application and the first question. I have been researching here for a while and usually find my answer, but I have an asshole, which is probably very obvious. I have an imageButton that doesn't seem to call the assigned method.

My XML for my imageButton:

<ImageButton 
 android:background="@null"
 android:onClick="click" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:id="@+id/imageButton1" 
 android:src="@drawable/stats" 
 android:layout_gravity="center_vertical">
</ImageButton>

My code is:

package com.talismancs;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class sheet extends Activity{
   private String selection;
   private String pick;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.sheet);
  Bundle extras = getIntent().getExtras(); 


  if(extras !=null) {
      // Get extra from .main and remove spaces
      String pick = extras.getString(selection);
      pick = pick.replace(" ", "");

      //Convert extra from string to int as ID and make image
      int imageResource = getResources().getIdentifier(pick, "drawable", getPackageName());
      ImageView iv = (ImageView) findViewById(R.id.imageView1);
      final Drawable image = getResources().getDrawable(imageResource);
      iv.setImageDrawable(image);

      // Populate tv from string
      TextView tv1 = (TextView) findViewById(R.id.textView4);
      TextView tv2 = (TextView) findViewById(R.id.textView5);
      TextView tv3 = (TextView) findViewById(R.id.textView6);
      TextView tv4 = (TextView) findViewById(R.id.textView7);
      TextView tv5 = (TextView) findViewById(R.id.textView8);
      int arrayresource = getResources().getIdentifier(pick, "array", getPackageName());
      String[] CharString = getResources().getStringArray(arrayresource);
      tv1.setText(CharString[0]);
      tv2.setText(CharString[1]);
      tv3.setText(CharString[2]);
      tv4.setText(CharString[3]);
      tv5.setText(CharString[4]);
    }

  }

public void onClick(View view) {
    Intent i = new Intent(sheet.this, stats.class);
    i.putExtra(pick, pick);
    startActivity(i);

}

}

It would seem simple? When I click the imageButton button, it does absolutely nothing!

Please, help.

EDIT: LOGCAT After selecting a spinner element that will lead us to this .sheet operation

> 03-16 06:15:38.977:
> INFO/ActivityManager(563): Displayed
> activity com.talismancs/.sheet: 766 ms
> 03-16 06:15:42.907:
> DEBUG/dalvikvm(1735): GC freed 448
> objects / 39160 bytes in 58ms 03-16
> 06:15:43.847:
> INFO/NotificationService(563):
> enqueueToast pkg=com.talismancs
> callback=android.app.ITransientNotification$Stub$Proxy@43773720
> duration=1  03-16 06:15:43.877:
> INFO/ActivityManager(563): Starting
> activity: Intent {
> comp={com.talismancs/com.talismancs.sheet} (has extras) }  03-16 06:15:43.917:
> WARN/InputManagerService(563): Window
> already focused, ignoring focus gain
> of:
> com.android.internal.view.IInputMethodClient$Stub$Proxy@43718320
> 03-16 06:15:44.527:
> INFO/ActivityManager(563): Displayed
> activity com.talismancs/.sheet: 646 ms

, imageButton

+3
6

. ur ClickListener.

, .

public class ExampleActivity extends Activity implements OnClickListener {
    protected void onCreate(Bundle savedValues) {
        ...
        Button button = (Button)findViewById(R.id.corky);
        button.setOnClickListener(this);
    }

    // Implement the OnClickListener callback
    public void onClick(View v) {
      // do something when the button is clicked
    }
    ...
}

.

+10

, , onCreate. , , XML- IMageButton. ImageButton android:onClick="click", click, onClick, XML ImageButton. .

+4

, onCreate. , Activity.

, :

public class sheet extends Activity {

    private String selection;
    private String pick;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void click(View view) {
        Intent i = new Intent(sheet.this, stats.class);
        i.putExtra(pick, pick);
        startActivity(i);
    }
}

. , .

.

+3
Button mybutton=new Button(ViewPagerSample.this);
mybutton.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }
});
+1

, .

public class sheet extends Activity implements onClickListener{

onCreate

iv.setOnClickListener(this);

. Else , .

0

OP, :

, , - ( , ) , . :

1) setEnabled(),

2) there may be a transparent layer above the buttons,

3) a transparent layer may even be transparent.

(The rest is trivial: some condition was true on the device where the program worked, but was always false on the new device ... It would be strange if the market application behaved this way, but not so unreasonably if you work in a company, which makes devices.)

0
source

All Articles