关闭

[android] (new buttons in java not in xml) share onclick in one activity,

40人阅读 评论(0) 收藏 举报
分类:

public class SecondAct extends Activity implements View.OnClickListener {

first should implements View.OnClickListener  then you can override onclick

@Override
public void onClick(View v) {
    switch ((Integer) v.getTag()){
        case 3:{}
        case 4:{}

why getTag? cuz I dont know how to setId for these buttons defined in java:

Button btf = new Button(this);
btf.setText("to fullscreen");
btf.setTag(4);
btf.setOnClickListener(this);

but I can setTag in them; an int or else type; then in that switch , notice should transfer to (Integer) or something you set in setTag.


note: dont forget break in case end; otherwise it goes to last step straight.








   
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1241次
    • 积分:140
    • 等级:
    • 排名:千里之外
    • 原创:14篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档