机器人的ImageButton的onClick方法不是要求 [英] android imageButton onClick method not calling

查看:140
本文介绍了机器人的ImageButton的onClick方法不是要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:(!除了XML作为它一堆可笑的表格式)发布全code
请忽略code,它不属于我的问题!我刚开的功能现在。以后我会清理。

Posting full code (except XML as it a bunch of ridiculous table formatting!) Please ignore the code that doesn't pertain to my question! I am just getting functionality right now. I'll clean it up later.

嘿,伙计们!第一个应用程序,并第一个问题。我在这里一段时间,通常是研究找到我的答案,但我管不着这可能是非常明显的。我似乎并没有被调用分配方法的ImageButton的。

Hey guys! First app and first question. I've researched here a while and usually find my answer but I have a bugger that is probably very obvious. I have an imageButton that doesn't seem to be calling the method assigned.

我的XML我的ImageButton:

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>

我的code:

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's 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);

}

}

看起来很简单吧?当我点击的ImageButton它绝对没有!

Seems simple right? When I click the imageButton it does absolutely nothing!

请帮忙。

编辑:LogCat中选择它得到我们这个活动.sheet一个微调项目后

LOGCAT After selecting a spinner item which gets us to this activity .sheet

> 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

After that is does nothing when I click the imageButton

推荐答案

您code是错误的。您还没有赋予ClickListener UR按钮。

Your code is wrong. You havent assigned ur button with ClickListener.

请参阅此示例code如何实现它。

Please see this sample code for how to implement it.

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
    }
    ...
}

您可以访问这个链接更多的参考。

You may visit this link for more reference.

这篇关于机器人的ImageButton的onClick方法不是要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆