Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 动作不再适用于图像按钮?_Android_Image - Fatal编程技术网

Android 动作不再适用于图像按钮?

Android 动作不再适用于图像按钮?,android,image,Android,Image,我有一个简单的应用程序,有两个按钮,可以触发一个通知。后来在编程过程中,由于设计更好,我想将普通按钮更改为图像按钮,因此我删除了中的普通按钮和但图像按钮,并将id更改回原始按钮1和按钮2,但现在它不再工作。我做错了什么?我是否必须对图像按钮进行与普通按钮不同的编程?我必须安装libarys或其他什么东西吗?请帮帮我 xml: 首先谢谢你 你变了吗 Button yourButton = (ImageButton) findViewById(R.id.btn); 到 此外,如果您向我们展示一些代

我有一个简单的应用程序,有两个按钮,可以触发一个通知。后来在编程过程中,由于设计更好,我想将普通按钮更改为图像按钮,因此我删除了中的普通按钮和但图像按钮,并将id更改回原始按钮1和按钮2,但现在它不再工作。我做错了什么?我是否必须对图像按钮进行与普通按钮不同的编程?我必须安装libarys或其他什么东西吗?请帮帮我

xml:

首先谢谢你

你变了吗

Button yourButton = (ImageButton) findViewById(R.id.btn);

此外,如果您向我们展示一些代码,我们将能够为您的查询提供更多帮助。

将这一行添加到您的ImageButtons中


请告诉我您在哪里定义按钮您在哪里定义了onclick事件??显示全部代码。这就是全部代码。。我没有更多的了。。但是它在正常按钮下工作。您需要向我们展示onCreate方法-@Override protected void onCreateBundle savedInstanceState{super.onCreatesavedInstanceState;setContentViewR.layout.activity_main;我再次编辑了它。这就是你想看到的吗?现在我已经输入了完整的代码,我什么都没有了:/i从未在我的代码中使用过这样一行:我必须把它放在哪里?你也可以粘贴你的onCreate方法吗?应该在那里,他们只是另一个问题。H当我点击按钮2次时,第一个通知会消失,而只有最新的通知会留下。现在,如果我按按钮1 3次,状态栏中的图标1会出现3次?你知道一个简单的代码吗?@DudeEffects抱歉,你应该问一个新问题
public class MainActivity extends ActionBarActivity {

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


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;

    }


    public void sendNotification(View view) {

        switch(view.getId()){

            case R.id.buttom1:
                Notification1();
                break;

            case R.id.buttom2:
                Notification2();
                break;


            }
         }

   private void Notification1() {

       NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
       builder.setAutoCancel(true);
       builder.setContentTitle("BasicNotification");
       builder.setContentText("Test");
       builder.setSmallIcon(R.drawable.icon1);

       Notification notification = builder.build();
       NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
       manager.notify((int) System.currentTimeMillis(), notification);

    }

 private void Notification2() {

       NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
       builder.setAutoCancel(true);
       builder.setContentTitle("BasicNotification");
       builder.setContentText("Test");
       builder.setSmallIcon(R.drawable.icon2);

       Notification notification = builder.build();
       NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
       manager.notify((int) System.currentTimeMillis(), notification);

    }

}
Button yourButton = (ImageButton) findViewById(R.id.btn);
ImageButton yourButton = (ImageButton) findViewById(R.id.btn);
 android:onClick="sendNotification"