显示从android中的片段视图中的php获取数据?

时间:2015-05-05 16:29:37

标签: android json listview android-fragments listadapter

我从php文件中获取数据,需要在listView上显示,扩展Fragment。

抛出onPostExecute()时出错:

The constructor SimpleAdapter(Commodities, ArrayList>, int, String[], int[]) is undefined

问题在于我的AsyncTask的onPostExecute():

@Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        ListAdapter adapter = new SimpleAdapter(Commodities.this,
                matchFixtureList, R.layout.list_item, new String[] {
                        TAG_SCRIPT, TAG_BUYSELL, TAG_TRADESELL, TAG_TARGET,
                        TAG_STOPLOSS, TAG_STATUS }, new int[] {
                        R.id.Script, R.id.BuySell, R.id.TradeSell,
                        R.id.Target, R.id.StopLoss, R.id.Status });
        setListAdapter(adapter);
    }

如何解决此错误?这是全班代码:

public class Commodities extends Fragment {

private String URL_ITEMS = "http://ourvadodara.ddns.net/NeptuneFinsol/commodities_fetch.php";
private static final String TAG_COMMODITIES = "commodities";
private static final String TAG_DATE = "date";
private static final String TAG_SCRIPT = "script";
private static final String TAG_BUYSELL = "buysell";
private static final String TAG_TRADESELL = "tradesell";
private static final String TAG_TARGET = "target";
private static final String TAG_STOPLOSS = "stoploss";
private static final String TAG_STATUS = "status";


JSONArray matchFixture = null;
ArrayList<HashMap<String, String>> matchFixtureList = new ArrayList<HashMap<String, String>>();

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.activity_bank__details,
            container, false);
    new GetFixture().execute();
    return rootView;
}

private class GetFixture extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected Void doInBackground(Void... arg) {
        ServiceHandler serviceClient = new ServiceHandler();
        Log.d("url: ", "> " + URL_ITEMS);
        String json = serviceClient.makeServiceCall(URL_ITEMS,
                ServiceHandler.GET);
        // print the json response in the log
        Log.d("Get match fixture response: ", "> " + json);
        if (json != null) {
            try {
                Log.d("try", "in the try");
                JSONObject jsonObj = new JSONObject(json);
                Log.d("jsonObject", "new json Object");
                // Getting JSON Array node
                matchFixture = jsonObj.getJSONArray(TAG_COMMODITIES);
                Log.d("json aray", "user point array");
                int len = matchFixture.length();
                Log.d("len", "get array length");
                for (int i = 0; i < matchFixture.length(); i++) {
                    JSONObject c = matchFixture.getJSONObject(i);
                    String Script = c.getString(TAG_SCRIPT);
                    Log.d("Script", Script);
                    String BuySell = c.getString(TAG_BUYSELL);
                    Log.d("BuySell", BuySell);
                    String TradeSell = c.getString(TAG_TRADESELL);
                    Log.d("TradeSell", TradeSell);
                    String Target = c.getString(TAG_TARGET);
                    Log.d("Target", Target);
                    String StopLoss = c.getString(TAG_STOPLOSS);
                    Log.d("StopLoss", StopLoss);
                    String Status = c.getString(TAG_STATUS);
                    Log.d("Status", Status);

                    // hashmap for single match
                    HashMap<String, String> matchFixture = new HashMap<String, String>();
                    // adding each child node to HashMap key => value
                    matchFixture.put(TAG_SCRIPT, Script);
                    matchFixture.put(TAG_BUYSELL, BuySell);
                    matchFixture.put(TAG_TRADESELL, TradeSell);
                    matchFixture.put(TAG_TARGET, Target);
                    matchFixture.put(TAG_STOPLOSS, StopLoss);
                    matchFixture.put(TAG_STATUS, Status);
                    matchFixtureList.add(matchFixture);
                }
            } catch (JSONException e) {
                Log.d("catch", "in the catch");
                e.printStackTrace();
            }
        } else {
            Log.e("JSON Data", "Didn't receive any data from server!");
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        ListAdapter adapter = new SimpleAdapter(Commodities.this,
                matchFixtureList, R.layout.list_item, new String[] {
                        TAG_SCRIPT, TAG_BUYSELL, TAG_TRADESELL, TAG_TARGET,
                        TAG_STOPLOSS, TAG_STATUS }, new int[] {
                        R.id.Script, R.id.BuySell, R.id.TradeSell,
                        R.id.Target, R.id.StopLoss, R.id.Status });
        setListAdapter(adapter);
    }
}

}

activity_commodities.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >

        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#0096BB"
            android:stretchColumns="*" >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#0096BB" >

                <TextView
                    android:id="@+id/date"
                    android:layout_width="100dp"
                    android:layout_margin="1dp"
                    android:gravity="center"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:text="Date &amp; Time"
                    android:textColor="#ffffff"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/Script"
                    android:layout_width="100dp"
                    android:layout_margin="1dp"
                    android:gravity="center"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:text="Script"
                    android:textColor="#ffffff"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/BuySell"
                    android:layout_width="100dp"
                    android:layout_margin="1dp"
                    android:gravity="center"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:text="BuySell"
                    android:textColor="#ffffff"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/TradeSell"
                    android:layout_width="100dp"
                    android:layout_margin="1dp"
                    android:gravity="center"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:text="Trade Sell"
                    android:textColor="#ffffff"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/Target"
                    android:layout_width="100dp"
                    android:layout_margin="1dp"
                    android:gravity="center"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:text="Target"
                    android:textColor="#ffffff"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/StopLoss"
                    android:layout_width="100dp"
                    android:layout_margin="1dp"
                    android:gravity="center"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:text="Stop Loss"
                    android:textColor="#ffffff"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/Status"
                    android:layout_width="100dp"
                    android:layout_margin="1dp"
                    android:gravity="center"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:text="Status"
                    android:textColor="#ffffff"
                    android:textSize="20sp" />
            </TableRow>

            <ListView
                android:id="@android:id/list"
                android:layout_width="fill_parent"
                android:layout_height="491dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:divider="#0096BB"
                android:dividerHeight="3dp" >
            </ListView>
        </TableLayout>
    </HorizontalScrollView>
</RelativeLayout>

MainActivity.java

公共类MainActivity扩展了FragmentActivity {

final Context context = this;

ActionBar bar;

// here we define the widgets required for implementing the drawer layout.
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private ExpandableListView mCategoryList;

// these are the arraylists for the categories and sub categories
private ArrayList<Category> category_name = new ArrayList<Category>();
private ArrayList<ArrayList<SubCategory>> subcategory_name = new ArrayList<ArrayList<SubCategory>>();
private ArrayList<Integer> subCatCount = new ArrayList<Integer>();

int previousGroup;

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

    // populate the arraylists
    this.getCatData();

    final ActionBar bar = getActionBar();
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
    bar.setTitle(R.string.title_activity_bank__details);

    // new code for drawer layout
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mCategoryList = (ExpandableListView) findViewById(R.id.left_drawer);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // defining the behavior when any group is clicked in expandable
    // listview
    mCategoryList.setOnGroupClickListener(new OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View view,
                int groupPosition, long id) {
            getActionBar().setDisplayShowTitleEnabled(true);
            if (groupPosition == 5) {
                getActionBar().setTitle(
                        Html.fromHtml("<font color='#0096BB'>"
                                + "Contact Us"
                                + "</font>"));
                Fragment fragment = new ContactUs();
                FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction()
                        .replace(R.id.frame_container, fragment).commit();
                mDrawerLayout.closeDrawers();
            } else if (groupPosition == 2) {
                getActionBar().setTitle(
                        Html.fromHtml("<font color='#0096BB'>"
                                + "Market View/News"
                                + "</font>"));
                Fragment fragment = new MarketViewNews();
                FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction()
                        .replace(R.id.frame_container, fragment).commit();
                mDrawerLayout.closeDrawers();
            }

            if (parent.isGroupExpanded(groupPosition)) {
                parent.collapseGroup(groupPosition);
            } else {
                if (groupPosition != previousGroup) {
                    parent.collapseGroup(previousGroup);
                }
                previousGroup = groupPosition;
                parent.expandGroup(groupPosition);
            }

            parent.smoothScrollToPosition(groupPosition);
            return true;
        }
        // }

    });

    // defining the behavior when any child is clicked in expandable
    // listview
    mCategoryList
            .setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

                @Override
                public boolean onChildClick(ExpandableListView parent,
                        View v, int groupPosition, int childPosition,
                        long id) {
                    getActionBar().setDisplayShowTitleEnabled(true);
                    // Toast.makeText(getApplicationContext(),
                    // mCategoryList+"", Toast.LENGTH_LONG).show();
                    Fragment fragment = null;
                    switch (groupPosition) {
                    case 0:
                        switch (childPosition) {
                        case 0:
                            getActionBar().setTitle(
                                    Html.fromHtml("<font color='#0096BB'>"
                                            + "Company Information"
                                            + "</font>"));
                            fragment = new Company_Info();

                            // Toast.makeText(getApplicationContext(),
                            // "helo",
                            // Toast.LENGTH_LONG).show();
                            break;
                        case 1:
                            getActionBar().setTitle(
                                    Html.fromHtml("<font color='#0096BB'>"
                                            + "Vision & Objectives"
                                            + "</font>"));
                            fragment = new Vision_Objectivies();

                            break;
                        }
                        break;
                    case 1:
                        switch (childPosition) {
                        case 1:
                            fragment = new Commodities();
                        case 4:
                            getActionBar()
                                    .setTitle(
                                            Html.fromHtml("<font color='#0096BB'>"
                                                    + "Fees Structure"
                                                    + "</font>"));
                            fragment = new Fees_Structure();
                            break;
                        case 5:
                            getActionBar().setTitle(
                                    Html.fromHtml("<font color='#0096BB'>"
                                            + "Bank Details" + "</font>"));
                            fragment = new Bank_Details();
                            break;
                        }
                        break;

                    case 3:
                        switch (childPosition) {
                        case 0:
                            getActionBar()
                                    .setTitle(
                                            Html.fromHtml("<font color='#0096BB'>"
                                                    + "Primary Details"
                                                    + "</font>"));
                            fragment = new PrimaryDetailsPms();
                            break;
                        case 1:
                            getActionBar().setTitle(
                                    Html.fromHtml("<font color='#0096BB'>"
                                            + "Stock Transfer Service"
                                            + "</font>"));
                            fragment = new StockTransferService();
                            break;
                        case 2:
                            getActionBar().setTitle(
                                    Html.fromHtml("<font color='#0096BB'>"
                                            + "Client Ledger" + "</font>"));
                            fragment = new ClientLedger();
                            break;
                        }
                        break;
                    case 4:
                        switch (childPosition) {
                        case 0:
                            getActionBar()
                                    .setTitle(
                                            Html.fromHtml("<font color='#0096BB'>"
                                                    + "Primary Details"
                                                    + "</font>"));
                            fragment = new PrimaryDetailsImp();
                            break;
                        case 1:
                            getActionBar()
                            .setTitle(
                                    Html.fromHtml("<font color='#0096BB'>"
                                            + "Advantages"
                                            + "</font>"));
                            fragment = new AdvantagesImp();
                            break;

                        }
                        break;

                    }
                    if (fragment != null) {
                        FragmentManager fragmentManager = getFragmentManager();
                        fragmentManager.beginTransaction()
                                .replace(R.id.frame_container, fragment)
                                .commit();
                    }

                    // calling CatWiseSearchResults with parameters of
                    // subcat code.
                    // CatWiseSearchResults will fetch items based on
                    // subcatcode.

                    ArrayList<SubCategory> tempList = new ArrayList<SubCategory>();
                    tempList = subcategory_name.get(groupPosition);
                    mCategoryList.setItemChecked(childPosition, true);
                    mCategoryList.setSelection(childPosition);

                    setTitle("asdfdfs");

                    mDrawerLayout.closeDrawer(mCategoryList);

                    return true;
                }
            });
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            R.drawable.ic_drawer, R.string.app_name, R.string.app_name) {

        @Override
        public void onDrawerClosed(View view) {
            // getActionBar().setDisplayShowTitleEnabled(true);
            // getActionBar().setTitle(Html.fromHtml("<font color='#000000'>"
            // + "Company info" + "</font>"));
            // getActionBar().setTitle("DrawerTitle");
            // if (mCategoryList.getCheckedItemPosition() == 0) {
            // getActionBar().setTitle(Html.fromHtml("<font color='#000000'>"
            // + "Company info" + "</font>"));
            // } else if (mCategoryList.getCheckedItemPosition() == 1) {
            // getActionBar().setTitle("Vision");
            // } else if (mCategoryList.getCheckedItemPosition() == 2) {
            // getActionBar().setTitle("future stock");
            // }
            // getActionBar().setIcon(R.drawable.neptune2);
            invalidateOptionsMenu();

        }

        @Override
        public void onDrawerOpened(View drawerView) {
            //getActionBar().setDisplayShowTitleEnabled(true);
        //  getActionBar().setIcon(R.drawable.neptune1);

            // getActionBar().setTitle("Home");
            // Toast.makeText(getApplicationContext(),
            // mCategoryList.getCheckedItemPosition()+"",
            // Toast.LENGTH_LONG).show();
            // if (mCategoryList.getCheckedItemPosition() == 0) {
            // getActionBar().setIcon(R.drawable.neptune1);
            // } else if (mCategoryList.getCheckedItemPosition() == 1) {
            // getActionBar().setIcon(R.drawable.home);
            // } else if (mCategoryList.getCheckedItemPosition() == 2) {
            // getActionBar().setIcon(R.drawable.neptune2);
            // }

            invalidateOptionsMenu();

        }

    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
    // if (savedInstanceState == null) {
    // // on first time display view for first nav item
    Fragment frag = new Home();
    if (frag != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.frame_container, frag).commit();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    // getMenuInflater().inflate(R.menu.start_screen, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }
    // Handle action buttons
    return true;
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}

public class expandableListViewAdapter extends BaseExpandableListAdapter {

    private LayoutInflater layoutInflater;
    private ArrayList<Category> categoryName = new ArrayList<Category>();
    ArrayList<ArrayList<SubCategory>> subCategoryName = new ArrayList<ArrayList<SubCategory>>();
    ArrayList<Integer> subCategoryCount = new ArrayList<Integer>();
    int count;
    // Typeface type;

    SubCategory singleChild = new SubCategory();

    public expandableListViewAdapter(Context context,
            ArrayList<Category> categoryName,
            ArrayList<ArrayList<SubCategory>> subCategoryName,
            ArrayList<Integer> subCategoryCount) {

        layoutInflater = LayoutInflater.from(context);
        this.categoryName = categoryName;
        this.subCategoryName = subCategoryName;
        this.subCategoryCount = subCategoryCount;
        this.count = categoryName.size();

        // Typeface font = Typeface.createFromAsset(getAssets(),
        // "amal.TTF");

    }

    @Override
    public void onGroupCollapsed(int groupPosition) {
        super.onGroupCollapsed(groupPosition);
    }

    @Override
    public void onGroupExpanded(int groupPosition) {
        super.onGroupExpanded(groupPosition);
    }

    @Override
    public int getGroupCount() {

        return categoryName.size();
    }

    @Override
    public int getChildrenCount(int i) {
        if (groupposition == 2 || groupposition == 5) {
            return 0;
        } else
            return (subCategoryCount.get(i));
    }

    @Override
    public Object getGroup(int i) {
        return categoryName.get(i).getCatName();
    }

    @Override
    public SubCategory getChild(int i, int i1) {

        ArrayList<SubCategory> tempList = new ArrayList<SubCategory>();
        tempList = subCategoryName.get(i);
        return tempList.get(i1);

    }

    int groupposition = 0;

    @Override
    public long getGroupId(int i) {
        groupposition = i;
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int i, boolean isExpanded, View view,
            ViewGroup viewGroup) {

        if (view == null) {
            view = layoutInflater.inflate(R.layout.expandablelistcategory,
                    viewGroup, false);
        }

        TextView textView = (TextView) view.findViewById(R.id.cat_desc_1);
        textView.setText(getGroup(i).toString());
        // textView.setTypeface(type);

        return view;

    }

    @Override
    public View getChildView(int i, int i1, boolean isExpanded, View view,
            ViewGroup viewGroup) {
        if (view == null) {
            view = layoutInflater.inflate(
                    R.layout.expandablelistviewsubcat, viewGroup, false);

        }

        singleChild = getChild(i, i1);

        TextView childSubCategoryName = (TextView) view
                .findViewById(R.id.subcat_name);
        // childSubCategoryName.setTypeface(type);

        childSubCategoryName.setText(singleChild.getSubCatName());

        return view;

    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }

    @Override
    public boolean areAllItemsEnabled() {
        return true;
    }

}

public void getCatData() {
    category_name.clear();
    Category categoryDetails = new Category();

    categoryDetails.setCatCode(10);
    categoryDetails.setCatName("Home");

    category_name.add(categoryDetails);

    categoryDetails = new Category();
    categoryDetails.setCatCode(20);
    categoryDetails.setCatName("Advisory Service");
    category_name.add(categoryDetails);

    categoryDetails = new Category();
    categoryDetails.setCatCode(30);
    categoryDetails.setCatName("Market View/News");
    category_name.add(categoryDetails);

    categoryDetails = new Category();
    categoryDetails.setCatCode(40);
    categoryDetails.setCatName("PMS");
    category_name.add(categoryDetails);

    categoryDetails = new Category();
    categoryDetails.setCatCode(50);
    categoryDetails.setCatName("Import Export Currency Trading");
    category_name.add(categoryDetails);

    categoryDetails = new Category();
    categoryDetails.setCatCode(60);
    categoryDetails.setCatName("Contact Us");
    // category_name.add(categoryDetails);

    category_name.add(categoryDetails);

    // ----Populate Sub Category Codes
    subcategory_name.clear();

    ArrayList<SubCategory> subCategoryMatches = new ArrayList<SubCategory>();

    SubCategory subCategoryMatch = new SubCategory();

    subCategoryMatch.setSubCatName("Company Information");
    subCategoryMatch.setSubCatCode("1001");
    subCategoryMatches.add(subCategoryMatch);

    subCategoryMatch = new SubCategory();
    subCategoryMatch.setSubCatName("Vision & Objective");
    subCategoryMatch.setSubCatCode("1002");
    subCategoryMatches.add(subCategoryMatch);

    subcategory_name.add(subCategoryMatches);
    subCatCount.add(subCategoryMatches.size());
    // ---

    // ADVISORY SERVICE
    subCategoryMatches = new ArrayList<SubCategory>();

    subCategoryMatch = new SubCategory();

    subCategoryMatch.setSubCatName("Future Stock");
    subCategoryMatch.setSubCatCode("2001");
    subCategoryMatches.add(subCategoryMatch);

    subCategoryMatch = new SubCategory();
    subCategoryMatch.setSubCatName("Commodities");
    subCategoryMatch.setSubCatCode("2002");
    subCategoryMatches.add(subCategoryMatch);

    subCategoryMatch = new SubCategory();
    subCategoryMatch.setSubCatName("NSE/BSE Cash");
    subCategoryMatch.setSubCatCode("2003");
    subCategoryMatches.add(subCategoryMatch);

    subCategoryMatch = new SubCategory();
    subCategoryMatch.setSubCatName("Currency");
    subCategoryMatch.setSubCatCode("2004");
    subCategoryMatches.add(subCategoryMatch);

    subCategoryMatch = new SubCategory();
    subCategoryMatch.setSubCatName("Fees Structure");
    subCategoryMatch.setSubCatCode("2005");
    subCategoryMatches.add(subCategoryMatch);

    subCategoryMatch = new SubCategory();
    subCategoryMatch.setSubCatName("Bank Details");
    subCategoryMatch.setSubCatCode("2006");
    subCategoryMatches.add(subCategoryMatch);

    subcategory_name.add(subCategoryMatches);
    subCatCount.add(subCategoryMatches.size());

    // EMPTY
    subCategoryMatches = new ArrayList<SubCategory>();

    subcategory_name.add(subCategoryMatches);
    subCatCount.add(subCategoryMatches.size());

    // ---
    // PMS
    subCategoryMatches = new ArrayList<SubCategory>();

    subCategoryMatch = new SubCategory();

    subCategoryMatch.setSubCatName("Primary Details");
    subCategoryMatch.setSubCatCode("5001");
    subCategoryMatches.add(subCategoryMatch);

    subCategoryMatch = new SubCategory();
    subCategoryMatch.setSubCatName("Stock Transfer Service");
    subCategoryMatch.setSubCatCode("5002");
    subCategoryMatches.add(subCategoryMatch);

    subCategoryMatch = new SubCategory();
    subCategoryMatch.setSubCatName("Client's Ledger");
    subCategoryMatch.setSubCatCode("5002");
    subCategoryMatches.add(subCategoryMatch);

    subcategory_name.add(subCategoryMatches);
    subCatCount.add(subCategoryMatches.size());

    // ---baby and kids

    subCategoryMatches = new ArrayList<SubCategory>();

    subCategoryMatch = new SubCategory();

    subCategoryMatch.setSubCatName("Primary Details");
    subCategoryMatch.setSubCatCode("6001");
    subCategoryMatches.add(subCategoryMatch);

    subCategoryMatch = new SubCategory();
    subCategoryMatch.setSubCatName("Advantages");
    subCategoryMatch.setSubCatCode("6002");
    subCategoryMatches.add(subCategoryMatch);

    subcategory_name.add(subCategoryMatches);
    subCatCount.add(subCategoryMatches.size());

}

@Override
public void onBackPressed() {
    AlertDialog.Builder alert = new AlertDialog.Builder(context);
    alert.setTitle("Are You sure want to exit");
    alert.setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub

                }
            });
    alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            Intent i = new Intent(MainActivity.this, Neptune.class);
            i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            i.putExtra("EXIT", true);
            startActivity(i);
            finish();
        }
    });

    AlertDialog alertDialog = alert.create();
    alertDialog.show();
}

}

0 个答案:

没有答案