0

I'm trying to list tweets authenticated users.I have created a FragmentUserTimeline which extends ListFragment.I take user session information successfully and bind them an adapter.But when i set it to setListAdapter there nothing show on FragmentUserTimeLine ListView. How can i fix it ?

   MainActivity.java

     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            Bundle extras = getIntent().getExtras();
            String userName = extras.getString("UserName");
            long userID = extras.getLong("UserID");
            String token = extras.getString("Token");
            String secret = extras.getString("Secret");

            TwitterSession session = Twitter.getSessionManager().getActiveSession();

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

            drawerFragment = (FragmentDrawer)
                    getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
            drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
            drawerFragment.setDrawerListener(this);

            // display the first navigation drawer view on app launch
            displayView(0);
        }
    private void displayView(int position) {
        Fragment fragment = null;
        ListFragment listFragment = null;
        String title = getString(R.string.app_name);
        switch (position) {
            case 0:
                fragment = new HomeFragment();
                title = getString(R.string.title_home);
                break;
            case 1:
                fragment = new FriendsFragment();
                title = getString(R.string.title_friends);
                break;
            case 2:
                fragment = new FragmentMessages();
                title =  getString(R.string.title_messages);
                break;

            case 3:
                listFragment = new FragmentUserTimeLine();
                title = getString(R.string.title_timeline);

            default:
                break;
        }

        if (fragment != null) {
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.container_body, fragment);
            fragmentTransaction.commit();

            // set the toolbar title
            getSupportActionBar().setTitle(title);
        }

        if (listFragment != null)
        {

            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.container_body, listFragment);
            fragmentTransaction.commit();

            getSupportActionBar().setTitle(title);


        }

Mainactivity.xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/container_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <include
                android:id="@+id/toolbar"
                layout="@layout/toolbar" />
        </LinearLayout>

        <FrameLayout
            android:id="@+id/container_body"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

    </LinearLayout>


    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:name="activity.FragmentDrawer"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer" />

</android.support.v4.widget.DrawerLayout>

fragment_usertimeline.xml

<LinearLayout 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"
    android:orientation="vertical"
    tools:context="activity.FragmentUserTimeLine" >

    <ListView android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:divider="#e1e8ed"
        android:dividerHeight="1dp"
        android:drawSelectorOnTop="false"/>

</LinearLayout>

FragmentUserTimeLine.java

public class FragmentUserTimeLine extends ListFragment  implements AdapterView.OnItemClickListener {
    public FragmentUserTimeLine() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_usertimeline, container, false);

        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);

        TwitterSession session = Twitter.getSessionManager().getActiveSession();

        String userName = session.getUserName();

        final SearchTimeline searchTimeline = new SearchTimeline.Builder()
                .query(userName)
                .build();
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(getActivity())
                .setTimeline(searchTimeline)
                .build();
        setListAdapter(adapter);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    }
Trinity
  • 486
  • 8
  • 27
  • I really need a solution! – Trinity Aug 24 '15 at 07:07
  • Do you have items in searchTimeline(which I'm assuming is the adapter's data source)? Do you add the fragment somewhere in your code? Can you post the layout where you place the fragment? – user Aug 24 '15 at 07:14
  • Sorry for late response. Yes I add fragment in my code.I have designed my fragment from this tutorial. http://www.androidhive.info/2015/04/android-getting-started-with-material-design/.I updated my question adding usertimeline layout adding. – Trinity Aug 25 '15 at 16:26

0 Answers0