@bonnell ok, so I have gotten the error to go away. Now I am getting no errors, but the tweets are not showing up. It just is showing the “no tweets” textview. Here is my code. I am very knew to Android development so I could be doing something stupid idk.
In the main activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new Twitter(authConfig), new Crashlytics());
My fragment:
public class NewsFragment extends ListFragment implements SwipeRefreshLayout.OnRefreshListener {
View rootView;
SwipeRefreshLayout swipeLayout;
TweetTimelineListAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SearchTimeline searchTimeline = new SearchTimeline.Builder()
.query("#fail")
.build();
adapter = new TweetTimelineListAdapter.Builder(getActivity())
.setTimeline(searchTimeline)
.build();
setListAdapter(adapter);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.newsfragment, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_refresh) {
updateFeed();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_news, container, false);
swipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.fragment_news);
swipeLayout.setOnRefreshListener(this);
return rootView;
}
@Override
public void onRefresh() {
updateFeed();
}
public void updateFeed(){
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) {
Snackbar.make(getView(), "The news could not be refreshed. Please try again soon!", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
}
Fragment XML:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height=“match_parent"
tools:context=“com.swissymania.android.nextspaceflight.NewsFragment"
android:id=”@+id/fragment_news”>
<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>