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

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.








            
阅读更多
个人分类: Android
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

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

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭