2

我有一个带有 3 个选项卡的操作栏活动。我有一个主要活动,我将 xml 发布到 web 服务并在 AsyncTaskj 中取回 xml。我正在初始化 AsncTask 中主要活动的静态变量。从主活动调用另一个活动,其中初始化操作栏。每个操作栏都有一个 ListFragment,我在其中使用静态变量。我从 2 个 List 活动访问静态变量没有问题,但在第一个 ListFragment m 中无法访问已初始化的静态变量。

编辑 1

我的主要活动

submit.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            GenerateXml gx=new GenerateXml();
            String requestXml=gx.generateXml(tv1.getText().toString(),tv2.getText().toString(),tv3.getText().toString(),tv4.getText().toString());
            myNewTask = new MyTask(requestXml);
            myNewTask.execute();
            Intent intent=new Intent(getApplicationContext(),TabActivity.class);
            startActivity(intent);
        }
    });

在我的 AsyncTask doInBackground

MainActivity.responseXml=responseXML;

创建选项卡的 Activity

public class TabActivity extends Activity {
    MyTask myNewTask;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        actionBar.setDisplayShowTitleEnabled(true);

        /** Creating All Tab */
        Tab tab = actionBar.newTab()
                .setText("All")
                .setTabListener(new CustomTabListener<AllMsgFragment>(this, "All", AllMsgFragment.class));
        //.setIcon(R.drawable.android);

        actionBar.addTab(tab);


        /** Creating Success Tab */
        tab = actionBar.newTab()
                .setText("Success")
                .setTabListener(new CustomTabListener<SuccessMsgFragment>(this, "Success", SuccessMsgFragment.class));
        //.setIcon(R.drawable.apple);


        actionBar.addTab(tab);   

        /** Creating Error Tab */
        tab = actionBar.newTab()
                .setText("Error")
                .setTabListener(new CustomTabListener<ErrorMsgFragment>(this, "error", ErrorMsgFragment.class));
        //.setIcon(R.drawable.apple);

        actionBar.addTab(tab);
    }
}

我的第一个 ListFragment:

public class AllMsgFragment extends ListFragment {
    public static String response;
    public ArrayList<HashMap<String, String>> msgDetails;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        response=MainActivity.responseXml;
        XmlToArrayList xmlArray=new XmlToArrayList();
        try {
            msgDetails=xmlArray.arrayListXml(response);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        ListAdapter adapter = new SimpleAdapter(getActivity(), msgDetails,
                R.layout.msg_preview,
                new String[] { "ObSystem", "ObName", "Msgstate"}, new int[] {
            R.id.bs, R.id.si, R.id.msgStatus});
        setListAdapter(adapter);

        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.e("first","1");
        /** Setting the multiselect choice mode for the listview */
        getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);     
    }
}
4

0 回答 0