我已经将v4 support lib用于FragmentTabHost
需要的是,当我将选项卡切换到另一个选项卡时,即调用
每次onCreateView() & onActivityCreated()。
这就是为什么我的代码性能很慢的原因。
还有其他解决办法吗?如何在片段选项卡中提高性能?
发布于 2013-04-26 06:46:29
我找到了解决办法。我在create中插入了所有的all服务和数据库事务代码。因为oncreate不是每次都打电话,直到毁灭不打电话。&另一个解决方案也是可用的,我们可以使用
fragment.show();
&fragment.hide()方法
发布于 2013-04-18 17:11:08
听起来像是设计的味道。
重新设计代码,以便异步完成繁重的工作。碎片应该能够快速地建立起来。如果为了使片段显示有用的信息,需要对其进行任何大型处理,则应在创建片段之后预先或异步完成该工作,并应通知该片段在完成工作后更新其内容。
发布于 2013-04-18 17:49:07
您应该注意的第一件事是观察计算/加载一大组数据时,应该放在与主UI线程不同的工作线程上。这样做的最佳选择(我认为)是使用AsyncTask。您可以在片段中使用这样的内容:
private class LoadData extends AsyncTask<Void, Void, Void>{
@Override
protected void onPreExecute(){
super.onPreExecute();
// this is the place where you can show
// progressbar for example to indicate the user
// that there is something which is happening/loading in the background
}
@Override
protected void doInBackground(Void... params){
// that's the place where you should do
// 'the heavy' process which should run on background thread
}
@Override
protected void onPostExecute(Void result){
super.onPostExecute();
// you should update your UI here.
// For example set your listview's adapter
// changes button states, set text to textview and etc.
}
}这是使您的选项卡工作的方法,faster.Hope,这将帮助您!:)
https://stackoverflow.com/questions/15500331
复制相似问题