安卓多个button怎么用switch设置事件
1个回答
展开全部
start = (Button) findViewById(R.id.button1);
stop = (Button) findViewById(R.id.button2);
start.setOnClickListener(mylistener );
stop.setOnClickListener(mylistener );
View.OnClickListener mylistener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
Log.d(TAG, "Start to recorder video\n");
start_recorde();
break;
case R.id.button2:
Log.d(TAG, "Stop to recorder video\n");
stop_recorde();
break;
default:
break;
}
}
};
stop = (Button) findViewById(R.id.button2);
start.setOnClickListener(mylistener );
stop.setOnClickListener(mylistener );
View.OnClickListener mylistener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
Log.d(TAG, "Start to recorder video\n");
start_recorde();
break;
case R.id.button2:
Log.d(TAG, "Stop to recorder video\n");
stop_recorde();
break;
default:
break;
}
}
};
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询