Android: ListView doesn't load only showing the TextView for twitter timeline

android
fabric
twitterkit

#1

i don’t know why but when i try to run it, it gets stuck on “Carregando… Favor Aguardar” and i dont know why. The listView doesn’t even load. why is this happening?

this is my project file

package com.sinappse.app.internal.explore.news;

import io.fabric.sdk.android.Fabric;

import android.app.ListActivity;
import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ListView;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.sinappse.app.R;
import com.sinappse.app.BuildConfig;


import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.ViewById;

import com.twitter.sdk.android.core.Callback;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.tweetui.TimelineResult;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.models.Tweet;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.TwitterCore;
import com.twitter.sdk.android.tweetui.TweetTimelineListAdapter;
import com.twitter.sdk.android.tweetui.TweetUi;
import com.twitter.sdk.android.tweetui.UserTimeline;

import java.util.List;


@EActivity(R.layout.news)
public class NewsActivity extends AppCompatActivity {

    @ViewById protected Toolbar toolbar;
    protected TextView emptyText;
    private ListView listview;


    @AfterViews protected void setupToolbar() {
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TwitterAuthConfig authConfig =  new TwitterAuthConfig(BuildConfig.TWT_KEY, BuildConfig.TWT_KEY_SEC);
        Fabric.with(this, new TwitterCore(authConfig), new TweetUi());



        //Load latest tweets from user
        setContentView(R.layout.news);
        emptyText = (TextView)findViewById(android.R.id.empty);
        listview = (ListView)findViewById(R.id.list);

        final UserTimeline userTimeline = new UserTimeline.Builder()
                .screenName(BuildConfig.TWT_NAME)
                .build();
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this)
                .setTimeline(userTimeline)
                .build();

        listview.setEmptyView(emptyText);
        listview.setAdapter(adapter);



        //Refresh latest tweets

        final SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
        final UserTimeline userTimeline2 = new UserTimeline.Builder()
                .screenName(BuildConfig.TWT_NAME)
                .build();
        final TweetTimelineListAdapter adapter2 = new TweetTimelineListAdapter.Builder(this)
                .setTimeline(userTimeline2)
                .build();


        listview.setEmptyView(emptyText);
        listview.setAdapter(adapter2);

        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swipeLayout.setRefreshing(true);
                adapter.refresh(new Callback<TimelineResult<Tweet>>() {
                    @Override
                    public void success(Result<TimelineResult<Tweet>> result) {
                        swipeLayout.setRefreshing(false);
                    }

                    @Override
                    public void failure(TwitterException exception) {
                        // Toast or some other action
                    }
                });
            }
        });
    }
    @OptionsItem(android.R.id.home) protected void homeSelected() { finish();}
}

and this is my xml file

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/primary"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

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


    <android.support.v4.widget.SwipeRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swiperefresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ListView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:backgroundTint="@color/com_facebook_blue"
            android:layout_weight="1"
            android:divider="#e1e8ed"
            android:dividerHeight="1dp"
            android:drawSelectorOnTop="false">
        </ListView>
    </android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>

#2

Thanks for reaching out on this @nicolasmelo, can you share the Logcat output when this is happening?


#3

this is what my logcat is showing right now when i start this activity. the list view doesn’t load and i can’t know why