启动后,Android应用程序无响应

时间:2015-03-31 07:27:32

标签: android android-activity tabs android-viewpager slidingdrawer

我正在制作一个Android应用程序。但是在启动活动之后,应用程序才会变为空白。什么都没发生。然后我必须强行关闭应用程序。以下是我的代码:

public class MainActivity extends FragmentActivity implements OnItemClickListener, ActionBar.TabListener
{
    ViewPager viewPager;
    ActionBar actionbar;
    TabsPagerAdapter mAdapter;
    private String[] tabs = {"SUMMARY", "STATS", "MAPS"};

    public static FragmentManager fragmentManager;

    private DrawerLayout drawerLayout;
    private ExpandableListView explistView;
    private String[] menuitems;
    private ActionBarDrawerToggle drawerListener;

    private GoogleMap googleMap;

    ExpandableListAdapter listAdapter;
//    ExpandableListView expListView;
    List<String> listDataHeader;
    HashMap<String, List<String>> listDataChild;

    public static final String icici_shared_pref = "ICICITotalAmt";

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        System.out.println("In Main Activity");

        viewPager=(ViewPager) findViewById(R.id.pager);
        actionbar = getActionBar();
        actionbar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#26C6DA")));
        mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

        viewPager.setAdapter(mAdapter);
//      actionbar.setHomeButtonEnabled(false);
        actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        //Adding Tabs
        for(String tab_name : tabs)
        {
            actionbar.addTab(actionbar.newTab().setText(tab_name).setTabListener(this));
        }
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() 
        {

            @Override
            public void onPageSelected(int position) 
            {
                // on changing the page
                // make respected tab selected
                actionbar.setSelectedNavigationItem(position);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) 
            {

            }

            @Override
            public void onPageScrollStateChanged(int arg0) 
            {

            }
        });

        menuitems=getResources().getStringArray(R.array.menuitems);
        drawerLayout=(DrawerLayout) findViewById(R.id.drawerLayout);

        explistView=(ExpandableListView) findViewById(R.id.expandabledrawerList);
        prepareListData2();
        listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);

        // setting list adapter
        explistView.setAdapter(listAdapter);

        explistView.setOnChildClickListener(new OnChildClickListener() 
        {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) 
            {
                // TODO Auto-generated method stub


                return false;
            }
        });

        drawerListener = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_closed)
        {
            @Override
            public void onDrawerClosed(View drawerView) 
            {
                // TODO Auto-generated method stub
                super.onDrawerClosed(drawerView);
            }

            @Override
            public void onDrawerOpened(View drawerView) 
            {
                // TODO Auto-generated method stub
                super.onDrawerOpened(drawerView);
            }
        };
        drawerLayout .setDrawerListener(drawerListener);
        getActionBar().setHomeButtonEnabled(true);
        getActionBar().setDisplayHomeAsUpEnabled(true);

    }                     // APPLICATIONS DOES NOT RESPOND AFTER THIS !!

    @Override
        public boolean onOptionsItemSelected(MenuItem item) 
        {
            // TODO Auto-generated method stub
        if(drawerListener.onOptionsItemSelected(item))
        {
            return true;
        }
        return super.onOptionsItemSelected(item);
        }

    @Override
        public void onConfigurationChanged(Configuration newConfig) 
    {
            // TODO Auto-generated method stub
            super.onConfigurationChanged(newConfig);
            drawerListener.onConfigurationChanged(newConfig);
    }

    @Override
        protected void onPostCreate(Bundle savedInstanceState) 
    {
            // TODO Auto-generated method stub
            super.onPostCreate(savedInstanceState);
            drawerListener.syncState();
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
    {
    }

    private void selectItem(int position) 
    {
        explistView.setItemChecked(position, true);
        setTitle(menuitems[position]);
    }

    public void setTitle(String title)
    {
        getActionBar().setTitle(title);
    }


    private void prepareListData2()
    {
        listDataHeader = new ArrayList<String>();
        listDataChild = new HashMap<String, List<String>>();

        // Adding child data
        listDataHeader.add("Overview");
        listDataHeader.add("Accounts");

     // Adding child of child's data
        List<String> overview = new ArrayList<String>();
        overview.add(" YOUR SUMMARY ");


        List<String> accounts = new ArrayList<String>();
        boolean flagicici=false,flagairtel=false,flagmobikwik=false,flagola=false,flagfreechrge=false,flagairtelmny=false,flagamex=false,flaghdfc=false;
        Uri accountslisturi = Uri.parse("content://sms/inbox");
        Cursor acccursor=getContentResolver().query(accountslisturi, new String[]{"_id","address","date","body"}, null, null, null);

        acccursor.moveToFirst();

        while(acccursor.moveToNext())
        {

            if(address.equals("MYSYS"))
            {
                if(flaghdfc==false)
                {
                    accounts.add("  SYSTEM MESSAGE ");
                    flaghdfc=true;
                }
            }
        }
        accounts.add(" CUSTOM TRANSACTIONS ");
        List<String> netBalance = new ArrayList<String>();
        List<String> refresh = new ArrayList<String>();


        listDataChild.put(listDataHeader.get(0), overview);
        listDataChild.put(listDataHeader.get(1), accounts);
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) 
    {
        // TODO Auto-generated method stub
        viewPager.setCurrentItem(tab.getPosition());

    }

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

    }

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

    }   
}

有什么想法吗?

0 个答案:

没有答案