0

Here is my situation. I have three tabs, now I painstakingly found out that these tabs have to be fragments and that is still something that am wrapping my head around I've gotten a good handle on them because the first fragment has a button that starts a new fragment, which we will call deduction fragment. Now here is my goal. I need the information that I gathered from the deduction fragment, which is being stored in a Shared Preferences file(which is also something I am new to, good handle on it but still a bit shaky) to be displayed in the list view that is on the tabbed fragment. One more thing that I think I should mention is that there is a textview on the tabbed fragment that I need to calculate the net income of the user.

Here is my code for the first tab activity that am stuck on: As you can see by all of the imports I have tried alot of stuff that still hurts my head.

package com.eulondk3.dellaj;

import java.util.ArrayList;
import java.util.List;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ListFragment;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class IncomeFragment extends ListFragment implements ActionBar.TabListener {

    private Fragment thisFragment;
    TextView tvChange;
    Button toDeductions;
    ListView listview1;
    List<String> deductionName = new ArrayList<String>();
    ArrayList <String> list = new ArrayList <String>();
    ArrayAdapter<String> adapter;

    public static final String DEDUCTIONS_PREFS_FILE = "deductionslist";
    SharedPreferences prefses = getActivity().getSharedPreferences(DEDUCTIONS_PREFS_FILE, 0);
    SharedPreferences.Editor edittor = prefses.edit();


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        ViewGroup gifraglayout = (ViewGroup) inflater.inflate(R.layout.gross_income_fragment, null);
        return gifraglayout;
    }

    @Override
    public void onTabReselected(Tab IncomeTab, FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTabSelected(Tab IncomeTab, FragmentTransaction ft) {
        // TODO Auto-generated method stub
        thisFragment = new IncomeFragment();
        ft.add(android.R.id.content, thisFragment);
        ft.attach(thisFragment);
    }

    @Override
    public void onTabUnselected(Tab IncomeTab, FragmentTransaction ft) {
        // TODO Auto-generated method stub
        ft.remove(thisFragment);

    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onViewCreated(view, savedInstanceState);

        tvChange = (TextView) getView().findViewById(R.id.tvgrossIncomeInfo);
        tvChange.setText("Your Goss Income is : $" + Userdata.user_income + ", would you like to add a deduction?");

        toDeductions = (Button) getView().findViewById(R.id.addDeduc);
        toDeductions.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent calltoDeductions = new Intent("com.eulondk3.dellaj.DEDUCT");
                startActivity(calltoDeductions);
            }
        });

        listview1 = (ListView) getView().findViewById(R.id.listView1);

    }}
4

1 回答 1

0

尝试将您获得的数据保存在 JSON 文件中(您可以使用 Java 的 GSON 库),然后尝试将 JSON 数据放入 String 并将其放入 SharedPreference 中。如果您想使用该数据,请检索 JSON,解析它(Java 的 GSON 库)并处理数据以获得结果。

于 2013-05-01T04:16:27.173 回答