User Timeline not showing in Android class that extends fragment

android

#1
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
     v = inflater.inflate(R.layout.twitter_layout, container, false);


    ListView listView = (ListView) v.findViewById(android.R.id.list);

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


    listView.setAdapter(adapter);

    mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swiperefresh);
    /*getData();*/
    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    // This method performs the actual data-refresh operation.
                    // The method calls setRefreshing(false) when it's finished.
                    if (isnetworkavaible()) {
                        // TODO: Use a more specific parent
                        //twitter_feeds();

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

                            @Override
                            public void failure(TwitterException exception) {
                                // Toast or some other action
                            }
                        });

                    }
                }
            }
    );

    if (isnetworkavaible()) {
       // twitter_feeds();
    } else {
       
    }
    return v;
}

I have added both my twitter the authentications on a class that extends application

@Override
public void onCreate() {
    super.onCreate();
    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig));
    mInstance = this;
}

#2

@StartappzKE Can you share your logcat output when trying to use the above code?


#3




#4

Hi @StartappzKE! Thanks for following up. I see a failed HTTP request in the logcat output. Are you behind a proxy or firewall? Thanks!


#5

i was using mobile data(tethering) and its unstable in some parts of Kenya .No proxy or firewall @todd


#6

Hi @StartappzKE! Thanks for following up. Does the same HTTP null pointer exception always appear when you build and run your app and navigate to this view? Thanks!


#7

@Todd yes it does i think its a Volley error because i am using Volley library to do http requests from my server


#8

I am also getting the same behavior in that the listview is not displaying anything. If I convert SwipeRefreshLayout to a LinearLayout then it works fine. Here is the problematic XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_layout"
    android:orientation="vertical"
    android:name="+id/"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView android:id="@id/android:empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal|center_vertical"
        android:text="No Tweets"/>

    <ListView android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:divider="#e1e8ed"
        android:dividerHeight="1dp"
        android:drawSelectorOnTop="false"/>
</android.support.v4.widget.SwipeRefreshLayout>

#9

Hello, I have the same issue above, I changed the tutorial and put SwipeRefreshLayout instead LinearLayout but its not displaying anything


#10

Hey there! Can you share your XML for this refresh view? Of note on SwipeRefreshLayout: “This layout should be made the parent of the view that will be refreshed as a result of the gesture and can only support one direct child.” (see https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html)

Referencing the XML above, this should work if you remove the TextView and have a single child.