How do I bind images from gallery to imageView at runtime? - android

I have a homework about doing whatsapp clone. But I have a problem. I have a add contact screen. Users choose an image from gallery and enter their name. When they click add button, list item will be added to chat activity. Screenshot is below. I have a person class like:
public class Person
{
private int id;
private string name;
private int imageId;
public Person(int id, string name, int imageId)
{
this.id = id;
this.name = name;
this.imageId = imageId;
}
public int Id // property
{
get { return id; } // get method
set { id = value; } // set method
}
public string Name // property
{
get { return name; } // get method
set { name = value; } // set method
}
public int ImageId // property
{
get { return imageId; } // get method
set { imageId = value; } // set method
}
public static explicit operator Java.Lang.Object(Person v)
{
throw new NotImplementedException();
}
}
public class PersonAdapter : BaseAdapter
{
private LayoutInflater mInflater;
private List<Person> personArrayList;
public PersonAdapter(Activity activity, List<Person> personArrayList)
{
this.mInflater = (LayoutInflater)activity.GetSystemService(Context.LayoutInflaterService);
this.personArrayList = personArrayList;
}
public override int Count => personArrayList.Count;
public override Object GetItem(int position)
{
return (Object)personArrayList.ElementAt(position);
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
convertView = mInflater.Inflate(Resource.Layout.List_Item, null);
TextView personName = (TextView)convertView.FindViewById(Resource.Id.name);
TextView personMessage = (TextView)convertView.FindViewById(Resource.Id.message);
ImageView personImage = (ImageView)convertView.FindViewById(Resource.Id.imageView);
Person person = personArrayList.ElementAt(position);
personName.Text = person.Name;
if(MainActivity.messages[person.Id].Count != 0)
{
personMessage.Text = MainActivity.messages[person.Id][MainActivity.messages[person.Id].Count - 1];
}
else
{
personMessage.Text = "";
}
personImage.SetImageResource(person.ImageId);
return convertView;
}
}
}
I have a personAdapter class and chat activity has only listView. So I am binding list to listView via adapter. I added some person manually to see chat menu. If I add images to drawable folder, there is no problem. But how do I add images to create new person. I can't add images to drawable at runtime. When I try to read images from external storage. They have no resource id. So person class do not accept that.
{
[Activity(Label = "#string/app_name", Theme = "#style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
public static List<Person> persons = new List<Person>();
public static Dictionary<int, List<string>> messages = new Dictionary<int, List<string>>();
PersonAdapter adapter;
private static int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
persons.Add(new Person(0,"Safa", Resource.Drawable.person));
persons.Add(new Person(1,"Melis", Resource.Drawable.person));
persons.Add(new Person(2,"Orkun", Resource.Drawable.person));
messages[0] = new List<string>();
messages[1] = new List<string>();
messages[2] = new List<string>();
messages[0].Add("Naber?");
messages[0].Add("Nasılsın?");
messages[1].Add("Nerdesin?");
messages[1].Add("Saat Kaç?");
messages[2].Add("Buluşalım mı?");
messages[2].Add("Kaçta?");
ListView listView = (ListView)FindViewById(Resource.Id.listView);
adapter = new PersonAdapter(this,persons);
listView.Adapter = adapter;
listView.ItemClick += (object sender, ItemClickEventArgs e) =>
{
Person person = persons[e.Position];
var intent = new Intent(this, typeof(ChatActivity));
intent.PutExtra("name", person.Name);
intent.PutExtra("id", person.Id);
this.StartActivity(intent);
};
FloatingActionButton fab = (FloatingActionButton)FindViewById(Resource.Id.fab);
fab.Click += delegate
{
var intent = new Intent(this, typeof(AddContactActivity));
this.StartActivity(intent);
};
if(Intent.GetStringExtra("person") != null)
{
Person newPerson = JsonConvert.DeserializeObject<Person> (Intent.GetStringExtra("person"));
persons.Add(newPerson);
messages.Add(newPerson.Id, new List<string>());
adapter.NotifyDataSetChanged();
}
}
}
}
AddContactActivity:
public class AddContactActivity : Activity
{
private ImageView imageView;
private Button loadButton;
private Button addButton;
private EditText nameEditText, surnameEditText;
private int index;
private string filename;
public static int SELECT_IMAGE = 1001;
Drawable drawable;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_addContact);
imageView = FindViewById<ImageView>(Resource.Id.load_image_imageView);
loadButton = FindViewById<Button>(Resource.Id.load_image_button);
addButton = FindViewById<Button>(Resource.Id.add_contact_button);
nameEditText = FindViewById<EditText>(Resource.Id.name_editText);
surnameEditText = FindViewById<EditText>(Resource.Id.surname_editText);
loadButton.Click += loadButtonClicked;
addButton.Click += addContactButtonClicked;
}
private void addContactButtonClicked(object sender, EventArgs e)
{
index = MainActivity.messages.Count;
Console.WriteLine(index);
Person newPerson = new Person(index, nameEditText.Text + " " + surnameEditText.Text, drawable.GetHashCode());
Intent intent = new Intent(this, typeof(MainActivity));
intent.PutExtra("person", JsonConvert.SerializeObject(newPerson));
StartActivity(intent);
}
private void loadButtonClicked(object sender, EventArgs e)
{
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) == (int)Permission.Granted)
{
Intent = new Intent();
Intent.SetType("image/*");
Intent.SetAction(Intent.ActionGetContent);
StartActivityForResult(Intent.CreateChooser(Intent, "Select Picture"), SELECT_IMAGE);
}
else
{
ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.ReadExternalStorage }, 12);
}
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if ((requestCode == SELECT_IMAGE) && (resultCode == Result.Ok) && (data != null))
{
Android.Net.Uri uri = data.Data;
Bitmap bitmap = MediaStore.Images.Media.GetBitmap(ContentResolver, uri);
imageView.SetImageBitmap(bitmap);
}
else
{
Toast.MakeText(this.ApplicationContext, "You haven't picked an image", ToastLength.Short).Show();
}
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
if (requestCode == 12)
{
if ((grantResults.Length == 1) && (grantResults[0] == Permission.Granted))
{
Intent = new Intent();
Intent.SetType("image/*");
Intent.SetAction(Intent.ActionGetContent);
StartActivityForResult(Intent.CreateChooser(Intent, "Select Picture"), SELECT_IMAGE);
}
}
else
{
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}

Do you want to achieve the result like this GIF?
Based on your code, you need serveral steps to achieve it.
First of all, we should use Convert Bitmap to Base64 string to achieve it, we can create a MyUtils.cs
public class MyUtils
{
public static string ConvertBitMapToString(Bitmap bitmap)
{
byte[] bitmapData;
using (MemoryStream stream = new MemoryStream())
{
bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 50, stream);
bitmapData = stream.ToArray();
}
string ImageBase64 = Convert.ToBase64String(bitmapData);
return ImageBase64;
}
public static Bitmap ConvertStringToBitmap(string mystr)
{
byte[] decodedString = Base64.Decode(mystr, Base64.Default);
Bitmap decodedByte = BitmapFactory.DecodeByteArray(decodedString, 0, decodedString.Length);
return decodedByte;
}
}
Then we should change the type of ImageId to string like following code.
public string ImageId // property
{
get { return imageId; } // get method
set { imageId = value; } // set method
}
Please change set the Image way in MainActiviy and Adapter.
Here is my demo, you can download it and refer to it.
https://github.com/851265601/TransferImageBtwActivities

Related

How to pass editText data to a string URL

I Want to make a url in one of my activities(UploadActivity.java) by taking information from 3 edit text boxes in another activity (LoginActivity.java) and passing that data into the other activity,
All the questions i found here on SO only prtains to a static URL i.e. www.blahblah.com/blah-blah.asp?My=Yes etc.
basicly the user must input his email, password and client ID(made by my company) and then it must be consolidated into a string
like this one
public static final String UPLOAD_URL =
"https://www.smartpractice.co.za/files-upload-ruben.asp?clientID=6868";
I'm using above url to upload user's location to the server.
Must I declare the edittext boxes in the activity? because at the moment it is only i the XML layout of the activity
I found this in another question and I don't understand how to implement it into my code.
Your edit text
EditText your_edit_text = (EditText) findViewById(R.id.your_id);
Get user data from edit text as fallows ..
String edit_text_data = your_edit_text.getText().toString();
Now when you need to put that data on url .. use this like ..
String your_url = "http://www.google.com=" + edit_text_data;
I want the Url here in this String in the "" quotations
public static final String UPLOAD_URL =
"https://www.smartpractice.co.za/files-upload-ruben.asp?MyForm=Yes";
UploadActivity JAVA
public class UploadActivity extends AppCompatActivity implements View.OnClickListener {
public static final String UPLOAD_URL = "https://www.smartpractice.co.za/files-upload-ruben.asp?MyForm=Yes";
public static final String UPLOAD_KEY = "image";
private int PICK_IMAGE_REQUEST = 1;
private Button buttonChoose;
private Button buttonUpload;
private ImageView imageView;
private Bitmap bitmap;
private Uri filePath;
#Override
public void onCreate(Bundle savedInstanceState ) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
init();
}
private void init(){
buttonChoose = findViewById(R.id.btnChoose);
buttonUpload = findViewById(R.id.btnUpload);
imageView = findViewById(R.id.imageView);
buttonChoose.setOnClickListener(this);
buttonUpload.setOnClickListener(this);
}
private void showFileChooser() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
#SuppressWarnings("deprecation")
#Override
public 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) {
filePath = data.getData();
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public String getStringImage(Bitmap bmp){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imageBytes = baos.toByteArray();
return Base64.encodeToString(imageBytes, Base64.DEFAULT);
}
private void uploadImage(){
#SuppressLint("StaticFieldLeak")
class UploadImage extends AsyncTask<Bitmap,Void,String> {
private ProgressDialog loading;
private RequestHandler rh = new RequestHandler();
#Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(UploadActivity.this, "Uploading Image", "Please wait...",true,true);
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(UploadActivity.this,s,Toast.LENGTH_LONG).show();
}
#RequiresApi(api=Build.VERSION_CODES.KITKAT)
#Override
protected String doInBackground(Bitmap... params) {
Bitmap bitmap = params[0];
String uploadImage = getStringImage(bitmap);
HashMap<String,String> data = new HashMap<>();
data.put(UPLOAD_KEY, uploadImage);
data.put("name",getFileName(filePath));
return rh.postRequest(UPLOAD_URL,data);
}
}
UploadImage ui = new UploadImage();
ui.execute(bitmap);
}
#Override
public void onClick(View v) {
if (v == buttonChoose) {
showFileChooser();
}
if(v == buttonUpload){
if(filePath!=null) {
uploadImage();
} else {
Toast.makeText(UploadActivity.this,"Select Image",Toast.LENGTH_LONG).show();
}
}
}
#RequiresApi(api=Build.VERSION_CODES.KITKAT)
String getFileName(Uri uri){
String result = null;
if (Objects.equals(uri.getScheme(), "content")) {
try (Cursor cursor=getContentResolver().query(uri, null, null, null, null)) {
if (cursor != null && cursor.moveToFirst()) {
result=cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
}
}
if (result == null) {
result = uri.getPath();
assert result != null;
int cut = result.lastIndexOf('/');
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return result;
}
}
**LoginActivity
the edit text boxes are in the XML layout so far **
public class LoginActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
}
In short Take editText values from LoginActivity and pass it to UploadActivity and use that information to build a URL in UploadActivity.
Take edittext values from LoginActivity & Pass the values to UploadActivity
Bind your views in onCreate method in LoginActivity (change the ids with yours) & pass the input to UploadActivity through Intent.
public class LoginActivity extends AppCompatActivity {
private EditText email,password,email;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
email = findViewById(R.id.email);
password = findViewById(R.id.password);
email = findViewById(R.id.clientID);
Button loginBtn = findViewById(R.id.loginBtn);
loginBtn.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
String emailAddress = email.getText().toString().trim();
String userPassword = password.getText().toString().trim();
//Pass the data to next activity
String clientId = clientID.getText().toString().trim();
Intent intent = new Intent(LoginActivity.this, UploadActivity.class);
intent.putExtra("clientId", clientId);
intent.putExtra("email", emailAddress);
intent.putExtra("password", userPassword);
startActivity(intent);
}
});
}
}
Use above information to build a URL in UploadActivity
#RequiresApi(api=Build.VERSION_CODES.KITKAT)
#Override
protected String doInBackground(Bitmap... params) {
Bitmap bitmap = params[0];
String uploadImage = getStringImage(bitmap);
HashMap<String,String> data = new HashMap<>();
data.put(UPLOAD_KEY, uploadImage);
data.put("name",getFileName(filePath));
Intent intent = getIntent();
String clientId = intent.getStringExtra("clientId");
Uri.Builder builder = new Uri.Builder();
builder.scheme("https")
.authority("ww.smartpractice.co.za")
.appendPath("files-upload-ruben.asp")
.appendQueryParameter("clientID", clientId);
String myUrl = builder.build().toString();
return rh.postRequest(myUrl,data);
}
Cheers :)

How to generate pdf file and give command to print that generated file in android

i need to generate a pdf file and give print that file how do i do it in android i used the dependency
implementation 'org.apache.pdfbox:pdfbox:2.0.0-RC3'
and i code pdf Adapter as follows
public class PdfCreateAdapter extends RecyclerView.Adapter<PdfCreateAdapter.MyViewHolder> {
private List<PDFModel> pdfModels;
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_pdf_creation, parent, false);
return new MyViewHolder(itemView);
}
#Override
public void onBindViewHolder(MyViewHolder holder, int position) {
PDFModel model = pdfModels.get(position);
if (model != null) {
if (model.isReceived()) {
holder.mReceivedTV.setVisibility(View.VISIBLE);
} else {
holder.mReceivedTV.setVisibility(View.GONE);
}
holder.mPriceTV.setText(model.getPrice());
holder.mNameTV.setText(model.getName());
int ratingDrawable = getRatingImage(model.getRating());
holder.mRateIM.setImageResource(ratingDrawable);
}
}
#Override
public int getItemCount() {
return pdfModels.size();
}
/**
* This is set from PDFCreateByXML class
* This is my own model. This model have to set data from api
*
* #param pdfModels
*/
public void setListData(List<PDFModel> pdfModels) {
this.pdfModels = pdfModels;
notifyDataSetChanged();
}
/**
* Set rating image
*
* #param rating this is getting from api and set to image by rate point
* #return
*/
private int getRatingImage(float rating) {
int image = 0;
if (rating == 0f) {
image = R.drawable.pdf_star_1;
} else if (rating == 0.5f) {
image = R.drawable.pdf_half_star_2;
} else if (rating == 1f) {
image = R.drawable.pdf_star_2;
} else if (rating == 1.5f) {
image = R.drawable.pdf_half_star_3;
} else if (rating == 2f) {
image = R.drawable.pdf_star_3;
} else if (rating == 2.5f) {
image = R.drawable.pdf_half_star_4;
} else if (rating == 3f) {
image = R.drawable.pdf_star_4;
} else if (rating == 3.5f) {
image = R.drawable.pdf_half_star_5;
} else if (rating == 4f) {
image = R.drawable.pdf_star_5;
} else if (rating == 4.5f) {
image = R.drawable.pdf_half_star_6;
} else if (rating == 5f) {
image = R.drawable.pdf_star_6;
}
return image;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
private final TextView mReceivedTV;
private final TextView mNameTV;
private final ImageView mRateIM;
private final TextView mPriceTV;
public MyViewHolder(View view) {
super(view);
mPriceTV = (TextView) view.findViewById(R.id.tv_price);
mReceivedTV = (TextView) view.findViewById(R.id.tv_received);
mNameTV = (TextView) view.findViewById(R.id.tv_name);
mRateIM = (ImageView) view.findViewById(R.id.iv_rate);
}
}
}
My pdf model that gets the data from xml
public class PDFModel {
private boolean isPending;
private boolean isReceived;
private String price;
private String name;
private float rating;
public boolean isPending() {
return isPending;
}
public void setPending(boolean pending) {
isPending = pending;
}
public boolean isReceived() {
return isReceived;
}
public void setReceived(boolean received) {
isReceived = received;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getRating() {
return rating;
}
public void setRating(float rating) {
this.rating = rating;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
/**
* Create dummy PDF model
*
* #return PDF Models
*/
public static List<PDFModel> createDummyPdfModel() {
PDFCreationUtils.filePath.clear();
PDFCreationUtils.progressCount = 1;
boolean isFirstReceivedItem = false;
List<PDFModel> pdfModels = new ArrayList<>();
for (int i = 0; i < 110; i++) {
Random rand = new Random();
int price = rand.nextInt((1000 - 200) + 1) + 200;
PDFModel model = new PDFModel();
if (!isFirstReceivedItem) {
model.setReceived(true);
isFirstReceivedItem = true;
} else {
model.setReceived(false);
}
model.setPrice(String.valueOf(price) + String.valueOf(".0 Rs."));
if (i % 4 == 0) {
model.setName("Umesh Kumar " + i);
} else {
model.setName("Ram Kumar " + i);
}
model.setRating(i % 3);
pdfModels.add(model);
}
return pdfModels;
}
}
The flowing code is for crate pdf
this is pdfcrattionacivity.java
public class PdfCreationActivity extends AppCompatActivity {
private boolean IS_MANY_PDF_FILE;
/**
* This is identify to number of pdf file. If pdf model list size > sector so we have create many file. After that we have merge all pdf file into one pdf file
*/
private int SECTOR = 100; // Default value for one pdf file.
private int START;
private int END = SECTOR;
private int NO_OF_PDF_FILE = 1;
private int NO_OF_FILE;
private int LIST_SIZE;
private ProgressDialog progressDialog;
/**
* Store all dummy PDF models
*/
private List<PDFModel> pdfModels;
private TextView btnPdfPath;
/**
* Share PDF file
*/
private Button btnSharePdfFile;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pdf_creation);
btnSharePdfFile = (Button) findViewById(R.id.btn_share_pdf);
btnPdfPath = (TextView) findViewById(R.id.btn_pdf_path);
findViewById(R.id.btn_create_pdf).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
requestPermission();
}
});
pdfModels = PDFModel.createDummyPdfModel();
RecyclerView rvShowDemo = (RecyclerView) findViewById(R.id.rv_show_demo);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
rvShowDemo.setLayoutManager(mLayoutManager);
PdfCreateAdapter pdfRootAdapter = new PdfCreateAdapter();
pdfRootAdapter.setListData(pdfModels);
rvShowDemo.setAdapter(pdfRootAdapter);
}
#Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 111 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
generatePdfReport();
}
}
private void requestPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 111);
} else {
generatePdfReport();
}
}
/**
* This is manage to all model
*/
private void generatePdfReport() {
// NO_OF_FILE : This is identify to one file or many file have to created
LIST_SIZE = pdfModels.size();
NO_OF_FILE = LIST_SIZE / SECTOR;
if (LIST_SIZE % SECTOR != 0) {
NO_OF_FILE++;
}
if (LIST_SIZE > SECTOR) {
IS_MANY_PDF_FILE = true;
} else {
END = LIST_SIZE;
}
createPDFFile();
}
private void createProgressBarForPDFCreation(int maxProgress) {
progressDialog = new ProgressDialog(this);
progressDialog.setMessage(String.format(getString(R.string.msg_progress_pdf), String.valueOf(maxProgress)));
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMax(maxProgress);
progressDialog.show();
}
private void createProgressBarForMergePDF() {
progressDialog = new ProgressDialog(this);
progressDialog.setMessage(getString(R.string.msg_progress_merger_pdf));
progressDialog.setCancelable(false);
progressDialog.show();
}
/**
* This function call with recursion
* This recursion depend on number of file (NO_OF_PDF_FILE)
*/
private void createPDFFile() {
// Find sub list for per pdf file data
List<PDFModel> pdfDataList = pdfModels.subList(START, END);
PdfBitmapCache.clearMemory();
PdfBitmapCache.initBitmapCache(getApplicationContext());
final PDFCreationUtils pdfCreationUtils = new PDFCreationUtils(PdfCreationActivity.this, pdfDataList, LIST_SIZE, NO_OF_PDF_FILE);
if (NO_OF_PDF_FILE == 1) {
createProgressBarForPDFCreation(PDFCreationUtils.TOTAL_PROGRESS_BAR);
}
pdfCreationUtils.createPDF(new PDFCreationUtils.PDFCallback() {
#Override
public void onProgress(final int i) {
progressDialog.setProgress(i);
}
#Override
public void onCreateEveryPdfFile() {
// Execute may pdf files and this is depend on NO_OF_FILE
if (IS_MANY_PDF_FILE) {
NO_OF_PDF_FILE++;
if (NO_OF_FILE == NO_OF_PDF_FILE - 1) {
progressDialog.dismiss();
createProgressBarForMergePDF();
pdfCreationUtils.downloadAndCombinePDFs();
} else {
// This is identify to manage sub list of current pdf model list data with START and END
START = END;
if (LIST_SIZE % SECTOR != 0) {
if (NO_OF_FILE == NO_OF_PDF_FILE) {
END = (START - SECTOR) + LIST_SIZE % SECTOR;
}
}
END = SECTOR + END;
createPDFFile();
}
} else {
// Merge one pdf file when all file is downloaded
progressDialog.dismiss();
createProgressBarForMergePDF();
pdfCreationUtils.downloadAndCombinePDFs();
}
}
#Override
public void onComplete(final String filePath) {
progressDialog.dismiss();
if (filePath != null) {
btnPdfPath.setVisibility(View.VISIBLE);
btnPdfPath.setText("PDF path : " + filePath);
Toast.makeText(PdfCreationActivity.this, "pdf file " + filePath, Toast.LENGTH_LONG).show();
btnSharePdfFile.setVisibility(View.VISIBLE);
btnSharePdfFile.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sharePdf(filePath);
}
});
}
}
#Override
public void onError(Exception e) {
Toast.makeText(PdfCreationActivity.this, "Error " + e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
private void sharePdf(String fileName) {
final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
ArrayList<Uri> uris = new ArrayList<Uri>();
File fileIn = new File(fileName);
Uri u = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID, fileIn);
uris.add(u);
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
try {
startActivity(Intent.createChooser(emailIntent, getString(R.string.send_to)));
} catch (ActivityNotFoundException e) {
Toast.makeText(this, getString(R.string.error_file), Toast.LENGTH_SHORT).show();
}
}
}
I am unable to get logic on how do i suppose to give command to print that generated PDF to printer
You'll need to connect to your printer and then send the PDDocument to the connected printer to print it. Something along the following lines should work.
public static PrintService choosePrinter() {
PrinterJob printJob = PrinterJob.getPrinterJob();
if(printJob.printDialog()) {
return printJob.getPrintService();
}
else {
return null;
}
}
public static void printPDF(String fileName, PrintService printer)
throws IOException, PrinterException {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(printer);
PDDocument doc = PDDocument.load(fileName);
doc.silentPrint(job);
}
Code referenced from this SO answer.

How to Using uri get image in RecyclerView?

I'm working on an app in the Android studio. Click the button in the Fragment to open a dialog box and include a picture and a brief description. (Pictures are taken from your gallery.) Click OK to close the dialog box and include the image and description in the RecyclerView that exists in the Fragment. But this code that I've woven has a description, but it doesn's image. I wanted to hear a solution to this, so I asked you a question.
I'd appreciate your reply!
To briefly explain how my code works, when I receive an image from the dialog box, I send the path (/storage/emulated/0/Pictures/a.jpg) of the file as a toast message, and as soon as the dialog is closed, the imagepath and description are transferred to the String form, and the imagepath is converted from Fragment to uri and changed to Bitmap using it to apply to RecyclerView.
Below is my code.
Fragment.java
btn_addlist = view.findViewById(R.id.btn_addlist);
btn_addlist.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DialogFragment_cus dialog = new DialogFragment_cus();
dialog.show(getActivity().getSupportFragmentManager(), "tag");
dialog.setDialogResult(new DialogFragment_cus.OnMyDialogResult() {
// result : uri, result2 : dlg_edtName, result3 : dlg_edtSubtitle
#Override
public void finish(String result, String result2, String result3) {
imageUri = result; RecyclerInputName = result2;
RecyclerInputSubtitle = result3;
Uri uri = Uri.parse("file://" + imageUri);
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), uri);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
RecyclerItem_cus item = new RecyclerItem_cus(bitmap, RecyclerInputName, RecyclerInputSubtitle);
mArrayList.add(0, item);
mAdapter.notifyDataSetChanged();
Toast.makeText(getActivity(), "finish.", Toast.LENGTH_SHORT).show();
}
});
}
});
DialogFragment.java
dlg_AddButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK);
startActivityForResult(intent, 1);
}
});
dlg_ok.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DialogFragment_cus fragment = new DialogFragment_cus();
String input1 = dlg_edtName.getText().toString();
String input2 = dlg_edtSubtitle.getText().toString();
if(fragment != null) {
if(mDialogResult != null ) {
mDialogResult.finish(name_Str, input1, input2);
}
}
dismiss();
}
});
dlg_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dismiss();
}
});
return view;
}
public void setDialogResult(OnMyDialogResult dialogResult){
mDialogResult = dialogResult;
}
public interface OnMyDialogResult{
void finish(String result, String result2, String result3);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1 && resultCode == RESULT_OK) {
try {
name_Str = getImageNameToUri(data.getData());
InputStream in = getActivity().getContentResolver().openInputStream(data.getData());
Bitmap img = BitmapFactory.decodeStream(in);
in.close();
dlg_ImageView.setImageBitmap(img);
dlg_ImageView.setBackgroundResource(android.R.color.white);
Toast.makeText(getActivity(), "name_Str : "+name_Str , Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public String getImageNameToUri(Uri uri) {
String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = getActivity().getContentResolver().query(uri, projection, null, null, null);
getActivity().startManagingCursor(cursor);
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(columnIndex);
}
RecyclerView_cusAdapter.java
#Override
public void onBindViewHolder(#NonNull final MyViewHolder myViewHolder, int i) {
final RecyclerItem_cus item = items.get(i);
if (item != null) {
Glide.with(context)
.load(item.getImage())
.asBitmap()
.format(DecodeFormat.PREFER_ARGB_8888)
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
myViewHolder.cus_img.setImageBitmap(resource);
}
});
myViewHolder.cus_title.setText(item.getTitle());
myViewHolder.cus_subtitle.setText(item.getSubTitle());
}
}
#Override
public int getItemCount() {
return this.items.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView cus_title;
TextView cus_subtitle;
ImageView cus_img;
public MyViewHolder(View itemView) {
super(itemView);
cus_title = itemView.findViewById(R.id.cus_title);
cus_subtitle = itemView.findViewById(R.id.cus_subtitle);
cus_img = itemView.findViewById(R.id.cus_img);
}
}
RecyclerItem_cus.java
public class RecyclerItem_cus {
private Bitmap image;
private String title;
private String subTitle;
public RecyclerItem_cus(Bitmap image, String title, String subTitle) {
this.image = image;
this.title = title;
this.subTitle = subTitle;
}
public Bitmap getImage() {
return image;
}
public String getTitle() {
return title;
}
public String getSubTitle() {
return subTitle;
}
You can try to use Glide with the File object directly :
Glide.with(mContext)
.load(new File(item.getImage())) // Uri of the picture
.into(myViewHolder.cus_img);

I want to save data in SecondActivity from FirstActivity using Room

I have three activities, I capture all data but one from DetailActivity upon button click and save in database using Room; My intention is to insert all these data into the database and start ReviewActivity so as to get the arraylist of reviews and also insert it in the database. Everything seems to work fine until when I want to view review offline because I believe it has been saved, reviews does not get loaded.
This is my DetailActivity,
TextView overview_tv; ImageView image_tv; TextView name_tv; TextView ratings; Context context; TextView release_date; ImageView backdrop_poster; private ExpandableHeightListView trailers; public static ArrayList<Youtube> youtube; public static ArrayList<Review> reviews; TrailerViewAdapter adapter; public static DataObject data; DataObject dataObject; ArrayList<Review> savedReview; private static final String IMAGE_URL = "http://image.tmdb.org/t/p/w185/"; private static final String THE_MOVIEDB_URL2 = "https://api.themoviedb.org/3/movie/"; private static final String MOVIE_QUERY2 = "api_key"; private static final String API_KEY2 = "6cc4f47bd4a64e0117e157b79072ae37"; private static String SEARCH_QUERY2 = "videos"; public static int movieId; Button viewReviews; Button favourite; String movieRating; private static final int YOUTUBE_SEARCH_LOADER = 23; private static final int REVIEW_SEARCH_LOADER = 24; File file; String name; String overview; String releaseDate; int switcher; public static ArrayList<Review> favouriteReviews; TextView trev; AppDatabase mDb; //Navigation arrow on the action bar #Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { NavUtils.navigateUpFromSameTask(this); } return super.onOptionsItemSelected(item); } #Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_detail); mDb = AppDatabase.getInstance(getApplicationContext()); youtube = new ArrayList<Youtube>(); reviews = new ArrayList<Review>(); adapter = new TrailerViewAdapter(this, youtube); //Credit to Paolorotolo #github trailers = findViewById(R.id.expandable_list); trailers.setAdapter(adapter); trailers.setExpanded(true); //Navigation arrow on the acton bar; check also override onOptionsItemSelected ActionBar actionBar = this.getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } context = getApplicationContext(); Intent intent = getIntent(); if (intent == null) { closeOnError(); } switcher = getIntent().getIntExtra("switch", 3); overview_tv = findViewById(R.id.overview); image_tv = findViewById(R.id.image); name_tv = findViewById(R.id.name); ratings = findViewById(R.id.ratings); release_date = findViewById(R.id.release_date); backdrop_poster = findViewById(R.id.backdrop_poster); trev = findViewById(R.id.review_show); viewReviews = findViewById(R.id.review_button); favourite = findViewById(R.id.favourite_button); addListenerOnRatingBar(ratings); if (switcher != 2) { favourite.setVisibility(View.INVISIBLE); dataObject = (DataObject) getIntent().getParcelableExtra("array"); final String favouriteName = dataObject.getName(); final String favouriteOverview = dataObject.getOverview(); final String favouriteReleaseDate = dataObject.getReleaseDate(); ArrayList<Youtube> savedTrailer = dataObject.getTrailers(); savedReview = dataObject.getMovieReviews(); movieRating = dataObject.getRating(); name_tv.setText(favouriteName); overview_tv.setText(favouriteOverview); ratings.setText("Rating: " + movieRating); release_date.setText("Release Date: " + favouriteReleaseDate);// Toast.makeText(this, "Testing Reviews " + savedReview.get(0).getAuthor(), Toast.LENGTH_SHORT).show(); String imagePath = name_tv.getText().toString() + "0i"; String backdropPath = name_tv.getText().toString() + "1b"; try { DataObjectAdapter.downloadImage(imagePath, image_tv, this); } catch (Exception e) { e.printStackTrace(); } try { DataObjectAdapter.downloadImage(backdropPath, backdrop_poster, context); } catch (Exception e) { e.printStackTrace(); } if (savedTrailer != null) { TrailerViewAdapter lv = new TrailerViewAdapter(DetailActivity.this, savedTrailer); trailers.setAdapter(lv); switcher = 3; } } else { name = getIntent().getStringExtra("Name"); overview = getIntent().getStringExtra("Overview"); final String image = getIntent().getStringExtra("Image"); movieId = getIntent().getIntExtra("movieId", 1); final String backdrop = getIntent().getStringExtra("backdrop"); releaseDate = getIntent().getStringExtra("releaseDate"); movieRating = getIntent().getStringExtra("rating"); Log.i("this", "switch " + switcher); name_tv.setText(name); overview_tv.setText(overview); ratings.setText("Rating: " + movieRating); release_date.setText("Release Date: " + releaseDate); //load backdrop poster Picasso.with(context) .load(IMAGE_URL + backdrop) .fit() .placeholder(R.drawable.placeholder_image) .error(R.drawable.placeholder_image) .into(backdrop_poster); Picasso.with(context) .load(IMAGE_URL + image) .fit() .placeholder(R.drawable.placeholder_image) .error(R.drawable.placeholder_image) .into(image_tv); getSupportLoaderManager().initLoader(YOUTUBE_SEARCH_LOADER, null, this); //getSupportLoaderManager().initLoader(REVIEW_SEARCH_LOADER, null, this); //loadTrailers(); //loadReviews(); //populateKeys(); } /** * Here manages the views(list) for reviews */ viewReviews.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View v) { if (switcher == 3) { startActivity(new Intent(DetailActivity.this, ReviewActivity.class) .putExtra("switch", 3)); } else { Log.i("this", "I am from initial" + switcher); startActivity(new Intent(DetailActivity.this, ReviewActivity.class).putExtra("id", movieId)); } } } ); favourite.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View v) { data = new DataObject(); data.setName(name); data.setOverview(overview); data.setRating(movieRating); data.setReleaseDate(releaseDate); data.setTrailers(youtube);// data.setMovieReviews(reviews); try { saveImage(name_tv.getText().toString() + "0i", image_tv); saveImage(name_tv.getText().toString() + "1b", backdrop_poster); } catch (IOException e) { e.printStackTrace(); } Toast.makeText(context, "The movie is saved as a favourite", Toast.LENGTH_LONG).show(); AppExecutors.getInstance().diskIO().execute(new Runnable() { #Override public void run() { mDb.dataDao().insertData(data); } }); startActivity(new Intent(DetailActivity.this, ReviewActivity.class).putExtra("id", movieId) .putExtra(ReviewActivity.EXTRA_DATA_ID, 20)); } } ); }
And my ReviewActivity
public class ReviewActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<ArrayList<Review>>{ public static ArrayList<Review> reviews; public static List<DataObject> favouriteReviews; public static RecyclerView reviewList; ArrayList<Review> r; private static final int REVIEW_SEARCH_LOADER = 24; private static final String MOVIE_QUERY3 = "api_key"; private static final String API_KEY3 = "6cc4f47bd4a64e0117e157b79072ae37"; private static String SEARCH_QUERY3 = "reviews"; private static final String THE_MOVIEDB_URL3 = "https://api.themoviedb.org/3/movie/"; private static int movId; public static final String EXTRA_DATA_ID = "extraDataId"; private static final int DEFAULT_TASK_ID = -1; private int mTaskId = DEFAULT_TASK_ID; DataObject data1; AppDatabase mDb; ReviewAdapter revAdapter; int loaderSwitch; #Override protected void onResume() { super.onResume(); } #Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_review); mDb = AppDatabase.getInstance(getApplicationContext()); reviews = new ArrayList<Review>(); favouriteReviews = new ArrayList<DataObject>(); reviewList = findViewById(R.id.review_list); LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext()); reviewList.setLayoutManager(layoutManager); reviewList.setHasFixedSize(true); int switcher = getIntent().getIntExtra("switch", 1); Intent intent = getIntent(); if (intent == null) { finish(); } Log.i("this", "swithcer " + switcher); Log.i("this loader", "Loader " + loaderSwitch); if (switcher == 3){ DataObject dataObject = (DataObject) getIntent().getParcelableExtra("ArrayOfReviews"); if (dataObject != null){ ArrayList<Review> movieReviews = dataObject.getMovieReviews(); Toast.makeText(this, "There are reviews saved", Toast.LENGTH_LONG).show(); revAdapter = new ReviewAdapter(this, movieReviews ); reviewList.setAdapter(revAdapter); } } else { movId = getIntent().getIntExtra("id", 20); revAdapter = new ReviewAdapter(this, reviews); reviewList.setAdapter(revAdapter); loadReviews(); //populateReview(); } DividerItemDecoration decoration = new DividerItemDecoration(this, VERTICAL); reviewList.addItemDecoration(decoration); } #Override protected void onStart() { super.onStart(); //loadReviews(); } public static URL buildUrl3(String stringUrl) { Uri uri = Uri.parse(THE_MOVIEDB_URL3).buildUpon() .appendPath(stringUrl) .appendPath(SEARCH_QUERY3) .appendQueryParameter(MOVIE_QUERY3, API_KEY3) .build(); URL url = null; try { url = new URL(uri.toString()); } catch (MalformedURLException exception) { Log.e(TAG, "Error creating URL", exception); } return url; } public void loadReviews(){ // COMPLETED (19) Create a bundle called queryBundle Bundle queryBundle = new Bundle(); // COMPLETED (20) Use putString with SEARCH_QUERY_URL_EXTRA as the key and the String value of the URL as the value// queryBundle.putString(SEARCH_QUERY_URL_EXTRA, url.toString()); // COMPLETED (21) Call getSupportLoaderManager and store it in a LoaderManager variable LoaderManager loaderManager = getSupportLoaderManager(); // COMPLETED (22) Get our Loader by calling getLoader and passing the ID we specified Loader<ArrayList<Review>> movieReviews = loaderManager.getLoader(REVIEW_SEARCH_LOADER); // COMPLETED (23) If the Loader was null, initialize it. Else, restart it. if (movieReviews == null) { loaderManager.initLoader(REVIEW_SEARCH_LOADER, queryBundle, this); } else { loaderManager.restartLoader(REVIEW_SEARCH_LOADER, queryBundle, this); } } #Override public Loader<ArrayList<Review>> onCreateLoader(int id, Bundle args) { return new AsyncTaskLoader<ArrayList<Review>>(this) { #Override protected void onStartLoading() { super.onStartLoading(); forceLoad(); } #Override public ArrayList<Review> loadInBackground() { String g = String.valueOf(movId); // Create URL object URL url = buildUrl3(g); // Perform HTTP request on the URL and receive a JSON response back String jsonResponse = ""; try { jsonResponse = getResponseFromHttpUrl(url); } catch (Exception e) { e.printStackTrace(); } reviews = MovieJsonUtils.parseReview(jsonResponse); return reviews; } }; } #Override public void onLoadFinished(Loader<ArrayList<Review>> loader, ArrayList<Review> dat) { if (reviews != null) { Intent intent = getIntent(); if (intent != null && intent.hasExtra(EXTRA_DATA_ID)) { //mButton.setText(R.string.update_button); if (mTaskId == DEFAULT_TASK_ID) { mTaskId = intent.getIntExtra(EXTRA_DATA_ID, DEFAULT_TASK_ID); AppExecutors.getInstance().diskIO().execute(new Runnable() { #Override public void run() { data.setMovieReviews(reviews); mDb.dataDao().updateData(data); //mDb.dataDao().insertData(data); final List<DataObject> task = mDb.dataDao().loadById(mTaskId); runOnUiThread(new Runnable() { #Override public void run() { populateUI(task); } }); } }); } } else { ReviewAdapter lv = new ReviewAdapter(ReviewActivity.this, reviews); reviewList.setAdapter(lv); } } } #Override public void onLoaderReset(Loader<ArrayList<Review>> loader) { }
Data gets loaded from MainActivity, the saved data is passed on to other activities as a parcellable bundle via intent, the passed data is displayed in DetailActivity but not in ReviewActivity.
Alternatively, if I can load reviews alongside YouTube keys from DetailActivity, I believe I can handle the database issue from there, but two Loaders wouldn't just work together, the app crashes; I am aware two AsyncTasks concurrently run together solved this problem, but I prefer to use Loaders because of performance on configuration change

Parcelable ArrayList is always empty

I want to pass ArrayList via Intent to another activity. However, the code doesn't give any errors but List is always empty. Any idea what i'm doing wrong ? ty
Activity1
private ArrayList<ResimBean> rbList = new ArrayList<ResimBean>();
Bitmap bmp = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] thumbArray = stream.toByteArray();
Uri selectedImageUri = data.getData();
String fotopath = getRealPathFromURI(selectedImageUri);
ResimBean rb = new ResimBean(Parcel.obtain());
// rb.setResim(bar);
rb.setThumbnail(thumbArray);
rb.setPath(fotopath);
rbList.add(rb);
Intent intent = new Intent(getApplicationContext(), ResimListActivity.class);
intent.putParcelableArrayListExtra("reslist",rbList);
startActivityForResult(intent, 100);
Activity2
Bundle extras = getIntent().getExtras();
if (extras != null) {
try {
Intent i = getIntent();
ArrayList<ResimBean> rbList = i.getParcelableArrayListExtra("reslist");
} catch (Exception ex) {
String msg = ex.getMessage();
}
}
Its not giving any error but list is always empty.
EDIT
Added the code how i fill in list.
EDIT 2
Something wrong with my Parcelable class or what ?
public class ResimBean implements Parcelable {
private int Id;
private int HataBildirimId;
private byte[] Resim;
private byte[] Thumbnail;
public byte[] getThumbnail() {
return Thumbnail;
}
public void setThumbnail(byte[] thumbnail) {
Thumbnail = thumbnail;
}
private String Path;
public String getPath() {
return Path;
}
public void setPath(String path) {
Path = path;
}
public int getHataBildirimId() {
return HataBildirimId;
}
public void setHataBildirimId(int hataBildirimId) {
HataBildirimId = hataBildirimId;
}
public int getId() {
return Id;
}
public void setId(int id) {
Id = id;
}
public byte[] getResim() {
return Resim;
}
public void setResim(byte[] resim) {
Resim = resim;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(HataBildirimId);
dest.writeByteArray(Resim);
dest.writeByteArray(Thumbnail);
}
public ResimBean(Parcel in) {
readFromParcel(in);
}
public void readFromParcel(Parcel in){
this.HataBildirimId = in.readInt();
this.Resim = new byte[in.readInt()];
this.Thumbnail = new byte[in.readInt()];
}
public static final Parcelable.Creator<ResimBean> CREATOR = new Parcelable.Creator<ResimBean>() {
#Override
public ResimBean createFromParcel(Parcel in) {
return new ResimBean(in);
}
#Override
public ResimBean[] newArray(int size) {
return new ResimBean[size];
}
};
The way you are showing, you create a new ArrayList<> and send it empty as extra via intent to the next activity.
Where exactly do you populate your ArrayList?
You should do something like this:
private ArrayList<ResimBean> rbList = new ArrayList<ResimBean>();
//populate rbList using adapter, then call intent
Intent intent = new Intent(getApplicationContext(), ResimListActivity.class);
intent.putParcelableArrayListExtra("reslist",rbList);
startActivityForResult(intent, 100);
Otherwise, the rbList you send as extra will always be empty. It sounds obvious but I don't know how you are doing it, so this is my best guess.
You can follow this tutorial:
http://aryo.lecture.ub.ac.id/android-passing-arraylist-of-object-within-an-intent/
I got it working like this
Bundle extras = this.getIntent().getExtras();
if (extras != null) {
try {
Intent i = getIntent();
ArrayList<ResimBean> rbList = (ArrayList<ResimBean>) i.getExtras().get("reslist");
Log.i("mytag", " "+i.getExtras().get("reslist").toString());
Log.i("mytag", " "+rbList.get(0).toString());
} catch (Exception ex) {
String msg = ex.getMessage();
}
}
With the rbList in Activity2 size=1,
With your code I was getting size=0

Categories

Resources