-1

I have plan to implement search function on a product based on name. The product are store in shoppingcarthelper.java as List. Another java file name as searchActivity.java is to preform the search function on List based on name of the product. How should i call the List on searchActivity.java? Mostly the example that i saw declare the array in the searchActivity.java or main activity file not in other java file. Below shows the shoppingcarthelper.java.

public static final String PRODUCT_INDEX = "PRODUCT_INDEX";

private static List<product> catalog;
private static Map<product, ShoppingCartEntry> cartMap = new 
HashMap<product, ShoppingCartEntry>();

public static List<product> getCatalog(Resources res){
    if(catalog == null) {
        catalog = new Vector<product>();
        catalog.add(new product("Tudung", res
                .getDrawable(R.drawable.tudung),res
                .getDrawable(R.drawable.tudung1),res
                .getDrawable(R.drawable.tudung2),
                "Tudung testing.", 15.00, 0.20));
        catalog.add(new product("Baju Kurung", res
                .getDrawable(R.drawable.bajukurung),res
                .getDrawable(R.drawable.bajukurung1),res
                .getDrawable(R.drawable.bajukurung2),
                "Baju kurung baju kurung.", 59.90, 0.50));
    }

    return catalog;

Here is my search function. How should i write my search function so it retrieve List from shoppingcarthelper.java?

    inputSearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int 
     arg3) {
            // When user changed the Text
            main_activity.this.adapter.getFilter().filter(cs);
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                                      int arg3) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
        }
    });
Cheong Charlene
  • 275
  • 1
  • 2
  • 12

1 Answers1

0

This is kind of a duplicate, but you pointed out that you don't know where to start so I'll try to help like this: Use this answer: Custom Adapter for List View, and instead of 'Item' => 'product', and at the activity:

ListAdapter customAdapter = new ListAdapter(this, R.layout.itemlistrow,
    shoppingcarthelper.getCatalog(getResources()));

Or whatever you call the class that resides in shoppingcarthelper.java

Community
  • 1
  • 1
Gavriel
  • 18,880
  • 12
  • 68
  • 105