mardi 19 mai 2015

how to select from one list to another list

I have a list of products. The view which shows the list of products and a selected product works fine. I have a list of categories. The list shows fine. I want to have a select in the list of categories go to a list of products. I will then limit the list of products to the one in that category and show only them.

My problem seems to be creating the Intent in the callback method.

Alert: n00b code follows:

CategoryListFragment.java has:

private Callbacks productListCallbacks = new Callbacks() {
    @Override
    public void onItemSelected(String id) {
        Intent productListIntent = new Intent(getApplicationContext(), ProductListActivity.class);
        productListIntent.putExtra("selectedCategory", id);
        startActivity(productListIntent);
    }
};

But getApplicationContext() here is not right. Because this inner class does not have access to the Activity?

If I instead declare this with:

 private static Callbacks productListCallbacks =

Then the startActivity method is not found.

I have tried the things I have seen, like "CategoryListFragment.this" instead of the getApplicationContext() call. Yes, some of this is just random thrashing around. I know.

Is creating an Intent within a Selected callback unusual? With what should I construct the Intent that I want. There is obviously something here which I do not grok....

Aucun commentaire:

Enregistrer un commentaire