简体   繁体   English

Android Fabric Twitter时间轴

[英]Android Fabric Twitter Timeline

I am trying to show a user timeline in an android fragment. 我正在尝试在android片段中显示用户时间轴。 My HomeFragment.java onCreate() looks like this: 我的HomeFragment.java onCreate()看起来像这样:

public class HomeFragment extends ListFragment {

@InjectView(android.R.id.list) ListView mTimeline;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
        mSectionNumber = getArguments().getInt(ARG_SECTION_NUMBER);
    }

    final UserTimeline userTimeline = new UserTimeline.Builder().screenName("fabric").build();
    final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter(getActivity(), userTimeline);
    setListAdapter(adapter);

}

And my fragment_home.xml has this listview: 我的fragment_home.xml具有以下列表视图:

<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@android:id/list"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"/>

HomeFragment is a fragment of HomeActivity. HomeFragment是HomeActivity的片段。 This code just shows an empty list. 此代码仅显示一个空列表。 How do I fix this problem? 我该如何解决这个问题? I would also like to know how setListAdapter(adapter); 我也想知道setListAdapter(adapter); works. 作品。 How does it know which list to set the adapter to since it can't be called on any particular list. 由于无法在任何特定列表上调用适配器,它如何知道将适配器设置为哪个列表。 I used this twitter fabric page for reference when writing this code. 编写此代码时,我将此Twitter面料页面用作参考。

Inflate your custom layout fragment_home.xml in the ListFragment by overriding onCreateView . 通过覆盖onCreateViewListFragment膨胀自定义布局fragment_home.xml。

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_home, container, false);
}

Your layout contains a ListView with the special @android:id/list id which identifies the ListView ListFragment's setListAdapter will use. 您的布局包含一个带有特殊@android:id/list id的ListView ,该ID标识ListView ListFragment的setListAdapter将使用。

Also, TweetTimelineListAdapter is just a ListAdapter . 另外, TweetTimelineListAdapter只是ListAdapter If you'd like to find your own ListView and set the adapter yourself, use an ordinary Fragment (not a ListFragment ). 如果您想找到自己的ListView并自行设置适配器,请使用普通的Fragment (而不是ListFragment )。

mTimeline.setListAdapter(adapter)  // mTimeline is a ListView

The docs include a ListFragment example . 该文档包括一个ListFragment示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM