我Fragment
在我的应用程序中使用了 3 秒。第三个是Listfragment
. Listfragment
我在in 中加载 twitter 提要onActvityCreated()
。
现在的问题是ListFragment
当我移动到 2nd 时创建了 2nd Fragment
,这意味着它开始加载 twitter 提要。直到在 3rd 收到提要Fragment
,这在慢速连接中需要很长时间,我的 2ndFragment
完全没有响应。我无法单击任何图标或滑动到第一个Fragment
。每次Fragment
销毁时都会发生这种情况。
代码如下:
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
Log.d("TwitterFragment", "onActivityCreated++++++");
try {
// tw = new TwitterTask();
// tw.execute(null);
final ConnectivityManager connection = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
if (connection.getNetworkInfo(0).isConnected() || connection.getNetworkInfo(1).isConnected()) {
AccessToken a = new AccessToken("something", "something");
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(Values.CONSUMER_KEY, Values.CONSUMER_SECRET);
twitter.setOAuthAccessToken(a);
int i = (int) twitter.getId();
User u = twitter.showUser(i);
Log.i("twitter", "user name" + u.getName());
statuses = twitter.getUserTimeline("something");
listAdapter.notifyDataSetChanged();
// Populate list with our static array of titles.
setListAdapter(listAdapter);
getListView().setCacheColorHint(Color.TRANSPARENT);
getListView().setDivider(null);
getListView().setPadding(10, 0, 10, 0);
setRetainInstance(true);
getListView().setClickable(false);
}
} catch (Exception e) {
// TODO: handle exception
Log.i("something", "Failed to get timeline: " + e.getMessage());
}
}
这是getView()
适配器的代码:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final tweetViewHolder tweet;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.twitterfeed_row, null);
tweet = new tweetViewHolder();
tweet.twitterText = (TextView) convertView.findViewById(R.id.tweet_text);
tweet.tweetTime = (TextView) convertView.findViewById(R.id.tweet_time);
convertView.setTag(tweet);
} else
tweet = (tweetViewHolder) convertView.getTag();
tweet.twitterText.setText(statuses.get(position).getText());
tweet.tweetTime.setText(statuses.get(position).getCreatedAt().toString());
return convertView;
}
class tweetViewHolder {
TextView twitterText;
TextView tweetTime;
// TextView txtThird;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
if (statuses == null)
return 0;
else
return statuses.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
if (statuses != null)
return statuses.get(position);
else
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
另外,如果没有网络,我会看到默认值ProgressDialog
。Listfragment
这怎么能控制?是否有任何方法可以被覆盖来监视它?
TIA