如何在FragmentTabHost添加tab后获取Fragment实例
1个回答
展开全部
贴个代码你:private Fargment f;
在onCreat()中:
final Handler hand = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
f = getSupportFragmentManager().findFragmentByTag("TAG1");//TAG1是-->newTabSpec("TAG1")
Log.e("aaaa", "=====获得的view1是:=====" + f);
}
};
new Thread() {
@Override
public void run() {
try {
Thread.sleep(1500);//休眠1.5s后就能获取到了
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Message msg = hand.obtainMessage();
hand.sendMessage(msg);
}
}.start();
在onCreat()中:
final Handler hand = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
f = getSupportFragmentManager().findFragmentByTag("TAG1");//TAG1是-->newTabSpec("TAG1")
Log.e("aaaa", "=====获得的view1是:=====" + f);
}
};
new Thread() {
@Override
public void run() {
try {
Thread.sleep(1500);//休眠1.5s后就能获取到了
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Message msg = hand.obtainMessage();
hand.sendMessage(msg);
}
}.start();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询