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

    // Try with DB
    mBusDbHelper = new BusDbAdapter(this);
    mBusDbHelper.open();

    listType = getIntent().getIntExtra("listType", 0);
    if (listType == 0) {
      Toast.makeText(this, "Internal error", Toast.LENGTH_LONG);
      Log.v(TAG, "Unable to get listType");
      finish();
    }

    String[] args = {"routeID", "stopName"};
    int[] resources = {R.id.listItemRouteID, R.id.listItemName};
    listAdapter = new SimpleAdapter(this, locationList, R.layout.list_item, args, resources);
    setListAdapter(listAdapter);

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent i = new Intent(view.getContext(), ConfirmationPage.class);
            HashMap<String, String> item = locationList.get(position);
            DataFetcher df = new DataFetcher();
            try {
              BusStop b = df.getStopById(Integer.parseInt(item.get("stopID").split("_")[1]));
              i.putExtra("busstop", b);
              i.putExtra("busroute", item.get("routeID"));
              i.putExtra("busroutedesc", item.get("routeDesc"));
              startActivity(i);
              finish();
              // if an exception occurs, nothing happens (for now).
            } catch (NumberFormatException e) {
              Log.v(TAG, "Error parsing stop id!");
              e.printStackTrace();
            } catch (IOException e) {
              Log.v(TAG, "Error fetching info!");
              e.printStackTrace();
            }
          }
        });

    registerForContextMenu(getListView());

    // populate list items
    fillList(mBusDbHelper);
    mBusDbHelper.close();
  }
  public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.deletelist);
    data = new DataBaseHelper(this);
    lv1 = (ListView) findViewById(R.id.List);
    bback = (Button) findViewById(R.id.back);
    bback.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            call();
          }
        });

    Bundle bundle = getIntent().getExtras();
    String name2 = bundle.getString("name1");
    Cursor c1 = data.getDataCallid(name2);
    while (c1.moveToNext()) {
      id1 = c1.getInt(0);
      System.out.println("IDs " + id1);
    }
    Cursor c = data.getDataCallList(id1);
    System.out.println("ID1 " + id1);
    while (c.moveToNext()) {

      n2 = c.getString(0);
      n3 = c.getString(1);
      results.add(n2 + "  " + n3);
      System.out.println("FName" + n2);
      System.out.println("LName" + n3);
      oname = n2 + n3;
    }
    Cursor c2 = data.getCallListid(n2, n3);
    while (c2.moveToNext()) {
      id2 = c2.getInt(0);
      System.out.println("IDs " + id2);
    }
    CheckBox cb = new CheckBox(this);
    lv1.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    lv1.setAdapter(
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, results));
    lv1.setTextFilterEnabled(true);
    lv1.setOnItemClickListener(this);
  }
  @Override
  public void onViewCreated(View root, Bundle savedInstanceState) {
    super.onViewCreated(root, savedInstanceState);

    fragmentHelper.onViewCreated(this, root);

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          public void onItemClick(
              final AdapterView<?> parent, final View view, final int position, final long id) {
            final AMenuItem<T> onClick = getOnClickAction();
            if (onClick != null) {
              onClick.onClick(((T) parent.getItemAtPosition(position)), getActivity());
            }
          }
        });

    getListView()
        .setOnItemLongClickListener(
            new AdapterView.OnItemLongClickListener() {
              @Override
              public boolean onItemLongClick(
                  AdapterView<?> parent, View view, int position, long id) {
                final T item = (T) parent.getItemAtPosition(position);

                final List<LabeledMenuItem<T>> menuItems = getMenuItemsOnLongClick(item);

                if (!menuItems.isEmpty()) {
                  final AMenuBuilder<LabeledMenuItem<T>, T> menuBuilder =
                      AMenuBuilder.newInstance(
                          AbstractMathEntityListFragment.this.getActivity(),
                          MenuImpl.newInstance(menuItems));
                  menuBuilder.create(item).show();
                }

                return true;
              }
            });
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Resources res = getResources();
    setContentView(R.layout.contact_list);
    ToolbarConfig toolbar = new ToolbarConfig(this, res.getString(R.string.contacts));

    // setup the about button
    Button button = toolbar.getToolbarRightButton();
    button.setText(res.getString(R.string.new_contact));
    button.setOnClickListener(this);

    toolbar.hideLeftButton();

    // initialize the list view
    ContactRepositoryInterface datasource =
        ContactRepositoryFactory.getInstance().getContactRepository(this, this);
    datasource.open();

    // Check if the user wants to prepopulate some awesomeness
    // This is awkward since we update the list asynchronously
    /*
    if(datasource.count() == 0) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setMessage("You have no contacts, want us to make some for you?")
                .setTitle("No Contacts")
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // Make some contacts.
                        createNewContacts();
                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener(){
                    public void onClick(DialogInterface dialog, int id) {
                        //Do nothing
                    }
                })
                .create()
                .show();
    }
    */

    contact_adapter = new ContactAdapter(this, R.layout.contact_list_item, datasource.all());
    setListAdapter(contact_adapter);
    datasource.close();

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    // setup context menu
    registerForContextMenu(lv);

    // Setup Search
    EditText search_box = (EditText) findViewById(R.id.search_box);
    search_box.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            // To change body of implemented methods use File | Settings |
            // File Templates.
          }

          @Override
          public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            ContactListActivity.this.contact_adapter.getFilter().filter(charSequence);
            filtered = true;
          }

          @Override
          public void afterTextChanged(Editable editable) {
            // To change body of implemented methods use File | Settings |
            // File Templates.
          }
        });
  }