一旦布局被创建,我想要一个按钮被自动点击,为此我使用了button.performClick()。
问题是它不起作用。看起来我不能在onCreate, onStart, onResume方法中做到这一点。按钮及其事件是在什么时候创建的,这样我就可以单击它了?
这
@Override
protected void onResume() {
super.onResume();
mybutton.performClick();
}不起作用。
发布于 2013-03-05 21:33:46
您需要使用ViewTreeObserver
ViewTreeObserver vto = mybutton.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
vto.removeOnGlobalLayoutListener(this);
mybutton.performClick();
}
});https://stackoverflow.com/questions/15225036
复制相似问题