1

I am making an android app with 6 users that I need to pull data for. I set up my Bundle args to hold two things; an int with its position number and a string with the user's name. This is done like such.

@Override
    public Fragment getItem(int position) {
        // getItem is called to instantiate the fragment for the given page.
        // Return a DummySectionFragment (defined as a static inner class
        // below) with the page number as its lone argument.
        Fragment fragment = new DummySectionFragment();
        Bundle args = new Bundle();
        args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
        switch (position) {
        case 0:
            args.putString(DummySectionFragment.ARG_USER_NAME, "user1");
        case 1:
            args.putString(DummySectionFragment.ARG_USER_NAME, "user2");
        case 2:
            args.putString(DummySectionFragment.ARG_USER_NAME, "user3");
        case 3:
            args.putString(DummySectionFragment.ARG_USER_NAME, "user4");
        case 4:
            args.putString(DummySectionFragment.ARG_USER_NAME, "user5");
        case 5:
            args.putString(DummySectionFragment.ARG_USER_NAME, "user6");
        }
        fragment.setArguments(args);
        return fragment;
    }

Afterwards in my DummySectionFragment I do this.

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        this.ourContainer = container;
        this.ourInflater = inflater;
        View rootView = inflater.inflate(R.layout.fragment_main_dummy,
                container, false);

        //TextView dummyTextView = (TextView) rootView.findViewById(R.id.following);

        this.userPic = (ImageView) rootView.findViewById(R.id.user_Icon);
        this.following = (TextView) rootView.findViewById(R.id.following);
        this.followers = (TextView) rootView.findViewById(R.id.followers);
        this.tweets = (TextView) rootView.findViewById(R.id.tweets);


        //THIS IS THE IMPORTANT PART
        Bundle args = getArguments();
        System.out.println("Current Number: " + args.getInt(ARG_SECTION_NUMBER));
        System.out.println("Current Name: " + args.getString(ARG_USER_NAME));
        this.userName = args.getString(ARG_USER_NAME);
        //THIS IS THE IMPORTANT PART


        m_orders = new ArrayList<Order>();
        m_Users = new ArrayList<twitUser>();
        this.m_adapter = new OrderAdapter(getActivity(), inflater, R.layout.row, m_orders);         
        //setListAdapter(this.m_adapter);

        ListView mListView;
        mListView = (ListView) rootView.findViewById(R.id.list);
        mListView.setAdapter(this.m_adapter);

        new DummySectionFragment.AsyncTest().execute();

        m_ProgressDialog = ProgressDialog.show(getActivity(),    
              "Please wait...", "Retrieving data ...", true);
        return rootView;
    }

However the print statements that I put in there to test always return something like this.

Current Number: 1

Current Name: user6

Current Number: 2

Current Name: user6

I have no idea why this is happening. If you need more of my code to understand I can provide that.

4

1 回答 1

1

您的 switch 中没有 break 语句,因此对于其他所有情况,它都属于“user6”情况。

于 2013-04-18T22:12:32.980 回答