检索被点击的视图的id [英] retrieving the id of the view that was clicked

查看:129
本文介绍了检索被点击的视图的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用

MyActivity延伸活动实现OnClickListener {

10+左右按键此活动引用,并具有 setOnClicklistener(本)呼吁每个按钮的方法。

  @覆盖
公共无效的onClick(视图v){
    //这里我需要得到被点击的视图的ID ...
    //根据被点击不同的操作需要被调用按钮...
    //如何获得被点击的按钮的ID ...
}


解决方案

  @覆盖
公共无效的onClick(视图v){
开关(v.getId()){
    案例R.id.btnCancel:
        //你的code该按钮的的onclick
        打破;
}

I'm using MyActivity extends Activity implements OnClickListener{

This activity references around 10+ buttons and has setOnClicklistener(this) method called on every button.

@Override 
public void onClick(View v){
    //here I need to get the id of the view that was clicked...
    //Depending on the button that was clicked different actions need to be called...
    //How do I get the ID of the button that was clicked...
}

解决方案

@Override 
public void onClick(View v){
switch(v.getId()){
    case R.id.btnCancel:
        //your code for onclick of that button
        break;
}

这篇关于检索被点击的视图的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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