how to transfer a bitmap received from gallery in an custom adapter

200
November 24, 2017, at 3:46 PM

I need to send an image received from gallery to an custom adapter in another activity. When i click o the button to proceed the transfer, nothing happens.

This is my CLASS:

public class Timbru implements Parcelable {
private Integer year;
private String country;
private Float value;
private Bitmap poza_timbru;
public Timbru(Integer year, String country, Float value, Bitmap poza_timbru) {
    this.year = year;
    this.country = country;
    this.value = value;
    this.poza_timbru=poza_timbru;
}
public Bitmap getPoza_timbru() {
    return poza_timbru;
}
public void setPoza_timbru(Bitmap poza_timbru) {
    this.poza_timbru = poza_timbru;
}
public static Creator<Timbru> getCREATOR() {
    return CREATOR;
}
public static void setCREATOR(Creator<Timbru> CREATOR) {
    Timbru.CREATOR = CREATOR;
}
public Integer getYear() {
    return year;
}
public void setYear(Integer year) {
    this.year = year;
}
public String getCountry() {
    return country;
}
public void setCountry(String country) {
    this.country = country;
}
public Float getValue() {
    return value;
}
public void setValue(Float value) {
    this.value = value;
}
@Override
public String toString() {
    return "Timbru{" +
            "year=" + year +
            ", country='" + country + '\'' +
            ", value=" + value +
            ", poza_timbru=" + poza_timbru +
            '}';
}
public Timbru(Parcel in) {
    this.year = in.readInt();
    this.country = in.readString();
    this.value = in.readFloat();
    this.poza_timbru=in.readParcelable(null);
}
public static Parcelable.Creator<Timbru> CREATOR = new Creator<Timbru>() {
    @Override
    public Timbru createFromParcel(Parcel parcel) {
        return new Timbru(parcel);
    }
    @Override
    public Timbru[] newArray(int i) {
        return new Timbru[i];
    }
};
@Override
public int describeContents() {
    return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
    parcel.writeInt(year);
    parcel.writeString(country);
    parcel.writeFloat(value);
    parcel.writeParcelable(poza_timbru, i);
}

}

This is my Custom Adapter:

public class TimbruAdapter extends ArrayAdapter {
private int resource;
private List<Timbru> objects;
private LayoutInflater inflater;

public TimbruAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List objects, LayoutInflater inflater) {
    super(context, resource, objects);
    this.inflater = inflater;
    this.resource = resource;
    this.objects = objects;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View row = inflater.inflate(this.resource, parent, false);
    TextView tvYear = (TextView) row.findViewById(R.id.tv_year_rowLayout);
    TextView tvCountry = (TextView) row.findViewById(R.id.tv_country_rowLayout);
    TextView tvValue = (TextView) row.findViewById(R.id.tv_value_rowLayout);
    ImageView imgTimbru = (ImageView)row.findViewById(R.id.imgView_stampAdded_rowLayout) ;
    Timbru timbru = objects.get(position);
    tvCountry.setText(timbru != null && timbru.getCountry() != null ? timbru.getCountry() : "");
    tvYear.setText(timbru != null && timbru.getYear() != null ? timbru.getYear().toString() : "");
    tvValue.setText(timbru != null && timbru.getValue() != null ? timbru.getValue().toString() : "");
    imgTimbru.setImageBitmap(timbru.getPoza_timbru());
    return row;
}

}

This is my InsertStampActivity, here is where I select the photo from gallery:

public class InsertStampActivity extends AppCompatActivity {
EditText et_year;
EditText et_country;
EditText et_value;
Intent intent;
Button insertStamp;
ImageView timbru_primit;
Bitmap bitmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_insert_stamp);
    initComponents();
    intent = getIntent();
}
private void initComponents() {
    et_year = (EditText) findViewById(R.id.et_year_insertStamp);
    et_country = (EditText) findViewById(R.id.et_country_insertStamp);
    et_value = (EditText) findViewById(R.id.et_value_insertStamp);
    //img_timbru=(ImageView)findViewById(R.id.imgView_stampAdded_insertStamp);
    insertStamp = (Button) findViewById(R.id.btn_insertStamp);
    insertStamp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (validation()) {
                Timbru timbru = createTimbruFromComponents();
                if (timbru != null) {
                    intent.putExtra(Constants.ADD_STAMP_KEY, timbru);
                    setResult(RESULT_OK, intent);
                    finish();
                }
            }
        }
    });
}
private Timbru createTimbruFromComponents() {
    Integer year = Integer.parseInt(et_year.getText().toString());
    String country = et_country.getText().toString();
    Float value = Float.parseFloat(et_value.getText().toString());
    Bitmap timbru = Bitmap.createBitmap(bitmap);
    return new Timbru(year, country, value, timbru);
}
private boolean validation() {
    if (et_year.getText() == null || et_year.getText().toString().trim().isEmpty() || et_year.getText().toString().length() < 4) {
        Toast.makeText(getApplicationContext(), "Year is not valid", Toast.LENGTH_SHORT).show();
    }
    if (et_country.getText() == null || et_country.getText().toString().trim().isEmpty()) {
        Toast.makeText(getApplicationContext(), "Country is not valid", Toast.LENGTH_SHORT).show();
    }
    if (et_value.getText() == null || et_value.getText().toString().trim().isEmpty()) {
        Toast.makeText(getApplicationContext(), "Value is not valid", Toast.LENGTH_SHORT).show();
    }
    return true;
}
public void imgBtn_insertImagine(View view) {
    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*"); //arata doar imagini, nu si video sau altceva
    startActivityForResult(intent, PICK_IMAGE_REQUEST);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK
            && data != null && data.getData() != null) {
        Uri uri = data.getData();
        try {
            bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
            timbru_primit = (ImageView) findViewById(R.id.imgView_stampAdded_insertStamp);
            timbru_primit.setImageBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), "Unable to open the picture", Toast.LENGTH_SHORT).show();
        }
    }
}

}

This is my MyCollectionActivity, here I show the stamps inserted in a ListView:

public class MyColectionActivity extends AppCompatActivity {
FloatingActionButton fltBtn_insert;
ListView listViewStamps;
List<Timbru> listStamps2 = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_colection);
    fltBtn_insert = (FloatingActionButton) findViewById(R.id.flBtn_insertNewStamp_myCollection);
    listViewStamps = (ListView) findViewById(R.id.lv_stampList_myCollection);
    Bitmap poza = BitmapFactory.decodeResource(getApplicationContext().getResources(),
            R.drawable.plus_timbru);
    Timbru timbru = new Timbru(2005,"Romania",20.3f,poza); //default
    listStamps2.add(timbru);
    TimbruAdapter adapter = new TimbruAdapter(getApplicationContext(), R.layout.row_layout, listStamps2, getLayoutInflater());
    listViewStamps.setAdapter(adapter);
    fltBtn_insert.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getApplicationContext(), InsertStampActivity.class);
            startActivityForResult(intent, Constants.ADD_STAMP_REQUEST_CODE);
        }
    });
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == Constants.ADD_STAMP_REQUEST_CODE && resultCode == RESULT_OK && data != null) {
        Timbru result = data.getParcelableExtra(Constants.ADD_STAMP_KEY);
        if (result != null) {
            listStamps2.add(result);
            TimbruAdapter currentAdapter = (TimbruAdapter) listViewStamps.getAdapter();
            currentAdapter.notifyDataSetChanged();
        }
    }
}
Rent Charter Buses Company
READ ALSO
android studio 3.0.1 showing unable to merge dex why?

android studio 3.0.1 showing unable to merge dex why?

I upgraded the android studio 2x

562
I need to display only part of web page on android web view but I couldn&#39;t do with using Jsoup

I need to display only part of web page on android web view but I couldn't do with using Jsoup

I need display only specific part of web page on my webview and I tried it using Jsoup but selected part is display without java-script functionality and CSS stylesJsoup display specified part but just only HTML elements and I can do nothing with it

254
Convert and download m3u8 to mp3 in Android

Convert and download m3u8 to mp3 in Android

Using the ffmpeg method I am able to download the mp4 file using

336