public static Type getType(String name) {
    Type t = new Type();
    ElementType et = get(name);
    t.setId(et.getId());
    t.setName(et.toString());

    return t;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_manage_goods);

    name = (TextView) findViewById(R.id.editTextName);
    mydb = new DBHelper(this);

    mydb.DoUpgrade();
    // mydb.insertPlace("Шкаф большой и длинный");
    // mydb.insertPlace("Кровать большой и длинный длинный длинный длинный длинный");

    imgView = (ImageView) findViewById(R.id.addPhoto);
    spinner = (Spinner) findViewById(R.id.addPlace);
    typeSpinner = (Spinner) findViewById(R.id.addType);

    placeList = new ArrayList<Place>();
    placeList = mydb.getAllPlaces();

    typeList = mydb.getAllTypes();

    Place addPlace = new Place();
    addPlace.setName("Добавить ...");
    placeList.add(addPlace);

    Type type = new Type();
    type.setName("Добавить....");
    typeList.add(type);

    ArrayAdapter<Type> typeAdapter =
        new AddTypeAdapter(getApplicationContext(), R.layout.type_spinner, typeList);
    typeSpinner.setAdapter(typeAdapter);

    ArrayAdapter<Place> adapter =
        new AddPlaceAdapter(getApplicationContext(), R.layout.spinner_item, placeList);
    spinner.setAdapter(adapter);

    spinner.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            // Log.d(DEBUG, String.valueOf(position));
            // Log.d(DEBUG, String.valueOf(placeList.size()));
            if ((placeList.size() - 1) == position) {
              Intent intent = new Intent(getApplicationContext(), AddPlaceActivity.class);
              startActivityForResult(intent, ADD_PLACE_REQUEST);
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });

    typeSpinner.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            // Log.d(DEBUG, String.valueOf(position));
            // Log.d(DEBUG, String.valueOf(placeList.size()));
            if ((typeList.size() - 1) == position) {
              Intent intent = new Intent(getApplicationContext(), AddTypeActivity.class);
              startActivityForResult(intent, ADD_TYPE_REQUEST);
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });
  }
  /** On activity result */
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // log.info("start");
    if (resultCode != RESULT_OK) return;

    switch (requestCode) {
      case ADD_PLACE_REQUEST:

        // log.info(data.getExtras().getString("Name"));
        // log.info(String.valueOf(data.getExtras().getLong("Id")));

        if (data.getExtras().getString("Name") instanceof String) {
          Place pl = new Place();
          pl.setName(data.getExtras().getString("Name"));
          pl.setID(Long.valueOf(data.getExtras().getLong("Id")).intValue());

          // log.info("before insert");
          placeList.add(0, pl);

          spinner.setSelection(0);
        }

        break;

      case ADD_TYPE_REQUEST:

        // log.info(data.getExtras().getString("Name"));
        // log.info(String.valueOf(data.getExtras().getLong("Id")));

        if (data.getExtras().getString("Name") instanceof String) {
          Type type = new Type();
          type.setName(data.getExtras().getString("Name"));
          type.setID(Long.valueOf(data.getExtras().getLong("Id")).intValue());

          // log.info("before insert");
          typeList.add(0, type);

          typeSpinner.setSelection(0);
        }

        break;

      case CAMERA_REQUEST:
        Bundle extras = data.getExtras();

        if (extras != null) {
          Bitmap yourImage = extras.getParcelable("data");
          // convert bitmap to byte
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          yourImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
          imgView.setImageBitmap(yourImage);
          byte imageInByte[] = stream.toByteArray();
          Log.e("output before conversion", imageInByte.toString());
          // Inserting Contacts
          Log.d("Insert: ", "Inserting ..");
          image = imageInByte;
        }
        break;
      case PICK_FROM_GALLERY:
        Bundle extras2 = data.getExtras();

        if (extras2 != null) {
          Bitmap yourImage = extras2.getParcelable("data");

          // convert bitmap to byte
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          yourImage.compress(Bitmap.CompressFormat.PNG, 100, stream);

          imgView.setImageBitmap(yourImage);

          byte imageInByte[] = stream.toByteArray();
          Log.e("output before conversion", imageInByte.toString());
          // Inserting Contacts
          Log.d("Insert: ", "Inserting ..");
          image = imageInByte;
        }

        break;
    }
  }