【问题标题】:How to use AppCompatActivity with Fabric to get Timeline?如何使用 AppCompatActivity 和 Fabric 来获取时间线?
【发布时间】:2015-09-16 14:15:25
【问题描述】:

我正在关注fabric's documentation 以获取时间表。如果我按照他们的指示使用 ListActivity 它工作正常。但我想添加自己的工具栏,所以我使用了 AppCompatActivity。这是我的 java 文件的一部分:

public class TimelineActivity extends AppCompatActivity{

public static final String QUERY = "QUERY";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_timeline);

    Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    SearchTimeline searchTimeline = new SearchTimeline.Builder()
            .query(getIntent().getStringExtra(QUERY))
            .build();
    final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this)
            .setTimeline(searchTimeline)
            .build();
    ListView tweetList = (ListView)findViewById(R.id.tweet_list);
    tweetList.setAdapter(adapter);

}

这是我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TimeLineActivity">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"/>

    </android.support.design.widget.AppBarLayout>


    <LinearLayout
        android:layout_below="@id/appbar"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView android:id="@id/android:empty"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_horizontal|center_vertical"
            android:text="Please wait . . ."/>

        <ListView android:id="@+id/tweet_list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:divider="#e1e8ed"
            android:dividerHeight="1dp"
            android:drawSelectorOnTop="false"/>
    </LinearLayout>
</RelativeLayout>

问题是,它没有显示任何结果。我被困在“请稍候......”文本视图。

【问题讨论】:

    标签: android twitter-fabric appcompatactivity


    【解决方案1】:

    自己回答,因为我没有扩展ListActivity,所以需要添加Id = empty的TextView,手动使用setEmptyView()。

        TextView emptyText = (TextView)findViewById(android.R.id.empty);
        ListView tweetList = (ListView)findViewById(R.id.tweet_list);
    
        tweetList.setEmptyView(emptyText);
        tweetList.setAdapter(adapter);
    

    【讨论】:

      猜你喜欢
      • 2015-10-19
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-23
      相关资源
      最近更新 更多