// Na odabir stavke menija.
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.addItemToList:
        Intent intent = new Intent(this, AddItem.class);
        intent.putExtra("listName", listName);
        startActivity(intent);
        finish();
        break;
      case R.id.refreshItems:
        Intent intent2 = new Intent(this, EditListItems.class);
        intent2.putExtra("listName", listName);
        startActivity(intent2);
        finish();
        break;

      case R.id.cleanItems:
        ArrayList<Item> items = list.getItems();
        int n = items.size();
        for (int i = 0; i < n; i++) {
          if (list.getItems().get(i).isDone()) {
            list.removeItem(i);
            i--;
            n--;
          }
        }

        String string = list.toXMLplist();
        FileOutputStream fos;
        try {
          fos = openFileOutput(listName, Context.MODE_PRIVATE);
          fos.write(string.getBytes());
          fos.close();
          Util.listChanged(listName, getApplicationContext());
        } catch (Exception e) {
          e.printStackTrace();
        }

        Intent intent3 = new Intent(getApplicationContext(), EditListItems.class);
        intent3.putExtra("listName", listName);
        startActivity(intent3);
        finish();
        break;
    }
    return true;
  }
 // Popunjavanje floating context menija.
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
   int index3 = info.position;
   String name1 = array_sort.get(index3);
   String[] name = name1.split(",");
   int broj = list.idByNameInArray(name[0]);
   switch (item.getItemId()) {
       // Editiranje Itema sa liste.
     case R.id.editItem:
       Intent intent2 = new Intent(this, EditItem.class);
       intent2.putExtra("listName", listName);
       intent2.putExtra("itemIndex", broj);
       startActivity(intent2);
       finish();
       break;
       // Brisanje Itema sa liste.
     case R.id.deleteItem:
       int index4 = info.position;
       String name3 = array_sort.get(index4);
       String[] name2 = name3.split(",");
       int num = list.idByNameInArray(name2[0]);
       list.removeItem(num);
       String string = list.toXMLplist();
       FileOutputStream fos;
       try {
         fos = openFileOutput(listName, Context.MODE_PRIVATE);
         fos.write(string.getBytes());
         fos.close();
         Util.listChanged(listName, getApplicationContext());
       } catch (Exception e) {
         e.printStackTrace();
       }
       Intent intent3 = new Intent(getApplicationContext(), EditListItems.class);
       intent3.putExtra("listName", listName);
       startActivity(intent3);
       finish();
       break;
     default:
       return super.onContextItemSelected(item);
   }
   return true;
 }