{"id":3647,"date":"2025-04-14T11:57:24","date_gmt":"2025-04-14T11:57:24","guid":{"rendered":"https:\/\/alsaeeddev.com\/?p=3647"},"modified":"2025-04-25T11:57:28","modified_gmt":"2025-04-25T11:57:28","slug":"barcode-scanner-invoice-generator-app-in-android-java","status":"publish","type":"post","link":"https:\/\/alsaeeddev.com\/shop\/barcode-scanner-invoice-generator-app-in-android-java\/","title":{"rendered":"Barcode Scanner Invoice Generator App in Android Java"},"content":{"rendered":"<p><strong>Introduction<\/strong><br \/>\nIn this tutorial, we will explore how to develop a Barcode Scanner Invoice Generator App in Android Java that allows users to scan barcodes, add products to a list, and generate a PDF invoice. This app is ideal for small businesses or retail stores that need a quick and efficient way to manage transactions. By the end of this guide, you&#8217;ll be able to build a fully functional barcode scanner invoice generator app using modern Android development tools.<\/p>\n<hr \/>\n<h2>Prerequisites<\/h2>\n<p>Before getting started, ensure you have the following:<\/p>\n<ul>\n<li>Android Studio installed<\/li>\n<li>Basic knowledge of Java\/Kotlin<\/li>\n<li>Dependencies for barcode scanning and PDF generation<\/li>\n<\/ul>\n<h2>Step 1: Adding Dependencies<\/h2>\n<p>To enable barcode scanning and PDF generation, add the following dependencies to your <code>build.gradle<\/code> file:<\/p>\n<pre><code>implementation 'com.google.mlkit:barcode-scanning:17.2.0'\r\nimplementation 'com.itextpdf:itext7-core:7.1.15'<\/code><\/pre>\n<hr \/>\n<h2>Step 2: Implement Barcode Scanner<\/h2>\n<p>To scan barcodes, use the Google ML Kit. Integrate the camera preview and process the scanned barcode:<\/p>\n<pre><code>BarcodeScannerOptions options =\r\n    new BarcodeScannerOptions.Builder()\r\n        .setBarcodeFormats(Barcode.FORMAT_ALL_FORMATS)\r\n        .build();\r\n\r\nBarcodeScanner scanner = BarcodeScanning.getClient(options);<\/code><\/pre>\n<p>Once a barcode is scanned, retrieve the product details and add them to a list.<\/p>\n<hr \/>\n<h2>Step 3: Displaying Items in RecyclerView<\/h2>\n<p>Create a <code>RecyclerView<\/code> adapter to show scanned products dynamically:<\/p>\n<pre><code>public class ProductAdapter extends RecyclerView.Adapter&lt;ProductAdapter.ViewHolder&gt; {\r\n    private List&lt;Product&gt; productList;\r\n    \r\n    @Override\r\n    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {\r\n        Product product = productList.get(position);\r\n        holder.name.setText(product.getName());\r\n        holder.price.setText(String.valueOf(product.getPrice()));\r\n    }\r\n}<\/code><\/pre>\n<hr \/>\n<h2>Step 4: Generating a PDF Invoice<\/h2>\n<p>Use iText7 to create a PDF file containing the product details and save it to device storage:<\/p>\n<pre><code>PdfWriter writer = new PdfWriter(filePath);\r\nPdfDocument pdfDoc = new PdfDocument(writer);\r\nDocument document = new Document(pdfDoc);\r\ndocument.add(new Paragraph(\"Invoice\"));\r\n\r\nfor (Product product : productList) {\r\n    document.add(new Paragraph(product.getName() + \" - \" + product.getPrice()));\r\n}\r\ndocument.close();<\/code><\/pre>\n<h3>Complete Code Here<\/h3>\n<hr \/>\n<h4>1. MainActivity.java<\/h4>\n<pre><code>\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n    Button btnCreatePDf;\r\n    Bitmap bitmap, scaledBitmap;\r\n    EditText etCustomerName;\r\n    private final String[] informationArray = new String[]{\"Name\", \"Company Name\", \"Address\", \"Phone\", \"Email\"};\r\n\r\n    private int srNumber;\r\n    String ItemName, price, Quantity, priceTotal;\r\n\r\n\r\n    private RecyclerView recyclerView;\r\n\r\n    private MyAdapter adapter;\r\n    private final List listItem = new ArrayList&lt;&gt;();\r\n    private final List fullCodeList = new ArrayList&lt;&gt;();\r\n\r\n\r\n    private static final int CAMERA_PERMISSION_REQUEST_CODE = 200;\r\n\r\n\r\n    private DecoratedBarcodeView barcodeView;\r\n\r\n    private final Map&lt;String, String&gt; map = new HashMap&lt;&gt;();\r\n\r\n    int startingIndex = 5;\r\n    String copyDecodeText;\r\n    int yAxisForValue = 280;\r\n    private List totalPricePerItemList = new ArrayList&lt;&gt;();\r\n    private String customerName;\r\n\r\n    String pattern = \"^[-+]?[\\\\d&amp;]*\\\\.?\\\\d+$\";\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        EdgeToEdge.enable(this);\r\n        setContentView(R.layout.activity_main);\r\n        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -&gt; {\r\n            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());\r\n            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);\r\n            return insets;\r\n        });\r\n        etCustomerName = findViewById(R.id.etCustomerName);\r\n        btnCreatePDf = findViewById(R.id.btnNext);\r\n        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logo_2);\r\n\r\n        recyclerView = findViewById(R.id.myRecyclerView);\r\n        barcodeView = findViewById(R.id.zxingBarcodeScanner);\r\n        barcodeView.setStatusText(\"\");\r\n\r\n        recyclerView.setLayoutManager(new LinearLayoutManager(this));\r\n        adapter = new MyAdapter(this, listItem, (position, quantity) -&gt; {\r\n            listItem.get(position).setItemQuantity(quantity);\r\n        });\r\n        recyclerView.setAdapter(adapter);\r\n\r\n        map.put(\"1244\", \"Cold Drink\");\r\n        map.put(\"0054\", \"Burger\");\r\n        map.put(\"0187\", \"Sandwich\");\r\n        map.put(\"7176\", \"Pizza\");\r\n\r\n        startScanning();\r\n        \/\/scaledBitmap = Bitmap.createScaledBitmap(bitmap,100,100,false);\r\n        ActivityCompat.requestPermissions(this, new String[]{\r\n                Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, PackageManager.PERMISSION_GRANTED);\r\n        {\r\n\r\n            \/\/  createPdf();\r\n            startScanning();\r\n            createPdf();\r\n        }\r\n\r\n    }\r\n\r\n\r\n    private void startScanning() {\r\n        barcodeView.decodeContinuous(new BarcodeCallback() {\r\n            @Override\r\n            public void barcodeResult(BarcodeResult result) {\r\n                \/\/ Handle the decoded result\r\n                String decodedText = result.getText();\r\n                \/\/ addItemToRecyclerView(decodedText);\r\n\r\n                if (decodedText.length() == 14) {\r\n                    \/\/ Check if barcode has been scanned before\r\n                    if (!fullCodeList.contains(decodedText)) {\r\n\r\n                        fullCodeList.add(decodedText);\r\n\r\n                        copyDecodeText = decodedText;\r\n\r\n                        \/\/ Extract the last 4 digits using substring\r\n                        double lastDigitPrice = Double.parseDouble(decodedText.substring(decodedText.length() - 4));\r\n\r\n                        String productId = copyDecodeText.substring(startingIndex, startingIndex + 4);\r\n\r\n                        if (String.valueOf(lastDigitPrice).matches(pattern) &amp;&amp; productId.matches(pattern)) {\r\n                            ItemModel itemModel = new ItemModel(lastDigitPrice, map.get(productId), 1);\r\n                            addItemToRecyclerView(itemModel);\r\n                        }\r\n                    }\r\n                }\r\n\r\n            }\r\n\r\n\r\n            @Override\r\n            public void possibleResultPoints(List resultPoints) {\r\n                \/\/ You can use this callback method to show visual cues on the viewfinder.\r\n            }\r\n\r\n\r\n        });\r\n    }\r\n\r\n\r\n    private void addItemToRecyclerView(ItemModel item) {\r\n        \/\/  listItem.add(item);\r\n        \/\/   adapter.addItem(item);\r\n        listItem.add(item);\r\n        adapter.notifyItemInserted(listItem.size() - 1);\r\n    }\r\n\r\n\r\n    private void createPdf() {\r\n        btnCreatePDf.setOnClickListener(v -&gt; {\r\n\r\n            if(etCustomerName.getText().length() != 0 &amp;&amp; adapter.getItemCount() != 0){\r\n\r\n                customerName = etCustomerName.getText().toString();\r\n\r\n                PdfDocument pdfDocument = new PdfDocument();\r\n                Paint paint = new Paint();\r\n                \/\/    paint.setLetterSpacing(0.01f);\r\n\r\n                PdfDocument.PageInfo pageInfo1 = new PdfDocument.PageInfo.Builder(595, 842, 1).create();\r\n                PdfDocument.Page myPage1 = pdfDocument.startPage(pageInfo1);\r\n                Canvas canvas = myPage1.getCanvas();\r\n\r\n\r\n                \/\/ insert the picture\r\n                int endPosition = pageInfo1.getPageWidth() - 100;\r\n                scaledBitmap = Bitmap.createScaledBitmap(bitmap, 100, 100, false);\r\n\r\n                canvas.drawBitmap(scaledBitmap, endPosition, 0, paint);\r\n\r\n                \/\/ draw a text as like invoice\r\n                paint.setTextAlign(Paint.Align.CENTER);\r\n                paint.setTextSize(32.0f);\r\n                paint.setColor(ContextCompat.getColor(this, R.color.green));\r\n                paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));\r\n                canvas.drawText(\"Invoice\", (float) pageInfo1.getPageWidth() \/ 2, 100, paint);\r\n\r\n\r\n                \/\/ customer name headiing\r\n                paint.setTextAlign(Paint.Align.LEFT);\r\n                paint.setTextSize(10.0f);\r\n                paint.setColor(Color.BLACK);\r\n                paint.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC));\r\n                canvas.drawText(\"Customer Name: \"+customerName, 80, 170, paint);\r\n\r\n\r\n          \/*  int endX = pageInfo1.getPageWidth() - 5;\r\n\r\n            float textWidth = paint.measureText(getCurrentDate());\r\n            float x = pageInfo1.getPageWidth() - textWidth;*\/\r\n\r\n                \/\/ date and time heading\r\n                paint.setTextAlign(Paint.Align.RIGHT);\r\n                canvas.drawText(\"Date: \" + getCurrentDate(), 590, 170, paint);\r\n                canvas.drawText(\"Time: \" + getCurrentTime(), 590, 180, paint);\r\n\r\n                \/\/draw rectangle stroke etc\r\n                paint.setTextAlign(Paint.Align.RIGHT);\r\n                paint.setStyle(Paint.Style.STROKE);\r\n                paint.setStrokeWidth(1);\r\n                \/\/draw rectangle\r\n                canvas.drawRect(10, 220, pageInfo1.getPageWidth() - 10, 250, paint);\r\n                \/\/ draw four line vertical, to make portions in rectangle\r\n                canvas.drawLine(100, 220, 100, 250, paint);\r\n                canvas.drawLine(300, 220, 300, 250, paint);\r\n                canvas.drawLine(430, 220, 430, 250, paint);\r\n                canvas.drawLine(500, 220, 500, 250, paint);\r\n\r\n\r\n                paint.setStrokeWidth(0);\r\n                paint.setStyle(Paint.Style.FILL);\r\n                paint.setTextSize(12.0f);\r\n                paint.setTextAlign(Paint.Align.LEFT);\r\n                paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));\r\n\r\n                \/\/ draw texts invoice data headings\r\n                canvas.drawText(\"Sr No.\", 15, 240, paint);\r\n                canvas.drawText(\"Item Name\", 105, 240, paint);\r\n                canvas.drawText(\"Price\", 305, 240, paint);\r\n                canvas.drawText(\"Qty\", 435, 240, paint);\r\n                canvas.drawText(\"Total\", 505, 240, paint);\r\n\r\n                srNumber = 0;\r\n                for (int sNo = 0; sNo &lt; listItem.size(); sNo++) { srNumber++; \/\/ draw values as like qty price item name etc canvas.drawText(srNumber + \"\", 17, yAxisForValue, paint); canvas.drawText(listItem.get(sNo).getItemName(), 106, yAxisForValue, paint); canvas.drawText(String.valueOf(listItem.get(sNo).getItemPrice()), 306, yAxisForValue, paint); canvas.drawText(String.valueOf(listItem.get(sNo).getItemQuantity()), 435, yAxisForValue, paint); canvas.drawText(calculateTotalPerItem(listItem.get(sNo).getItemPrice(), listItem.get(sNo).getItemQuantity()), 508, yAxisForValue, paint); yAxisForValue += 20; } yAxisForValue += 20; \/\/ draw line below of value and above of total canvas.drawLine(300, yAxisForValue, pageInfo1.getPageWidth() - 10, yAxisForValue, paint); yAxisForValue += 20; \/\/ draw texts as like total canvas.drawText(\"Sub Total\", 306, yAxisForValue, paint); canvas.drawText(String.valueOf(calculateSubTotal()), 508, yAxisForValue, paint); canvas.drawText(\":\", 435, yAxisForValue, paint); yAxisForValue += 20; canvas.drawText(\"Tax (5%)\", 306, yAxisForValue, paint); canvas.drawText(String.valueOf(calculateTax()), 508, yAxisForValue, paint); canvas.drawText(\":\", 435, yAxisForValue, paint); Paint paint2 = new Paint(); paint2.setStrokeWidth(1); \/\/ Set the stroke width to 5 (adjust as needed) paint2.setColor(ContextCompat.getColor(this, R.color.black)); \/\/ Set the stroke color to black paint2.setStyle(Paint.Style.STROKE); \/\/ Set the style to fill and stroke yAxisForValue += 35; \/\/ this value uses for top int bottom = yAxisForValue + 45; paint.setColor(ContextCompat.getColor(this, R.color.green)); canvas.drawRect(300, yAxisForValue, pageInfo1.getPageWidth() - 10, bottom, paint); canvas.drawRect(300, yAxisForValue, pageInfo1.getPageWidth() - 10, bottom, paint2); int yValueForGrandTotal = bottom - yAxisForValue; int calc = yValueForGrandTotal \/ 3; int finalCalc = calc * 2; yAxisForValue += finalCalc; paint.setColor(Color.WHITE); paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); paint.setTextSize(16.0f); canvas.drawText(\"Total\", 320, yAxisForValue, paint); canvas.drawText(String.valueOf(calculateSubTotal() + calculateTax()), 515, yAxisForValue, paint); paint.setColor(ContextCompat.getColor(this, R.color.black)); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(8.0f); canvas.drawText(\"Invoice Number: \" + System.currentTimeMillis(), 17, pageInfo1.getPageHeight() - 20, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.drawText(\"Generate by Al Saeed\", pageInfo1.getPageWidth() - 17, pageInfo1.getPageHeight() - 20, paint); pdfDocument.finishPage(myPage1); String folderName = \"AlsaeedFolder\"; \/\/ Define your custom folder name File customFolder = new File(Environment.getExternalStorageDirectory(), folderName); if (!customFolder.exists()) { customFolder.mkdirs(); \/\/ Create the folder if it doesn't exist } File file = new File(customFolder, \"myPDF.pdf\"); try { if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {\r\n                        pdfDocument.writeTo(Files.newOutputStream(file.toPath()));\r\n                    } else {\r\n                        pdfDocument.writeTo(new FileOutputStream(file));\r\n                    }\r\n                } catch (IOException e) {\r\n                    throw new RuntimeException(e);\r\n                }\r\n\r\n                Toast.makeText(this, \"File save in \" + file.getAbsolutePath(), Toast.LENGTH_SHORT).show();\r\n                \/\/ pdfDocument.close();\r\n\r\n\r\n                \/\/ Open the PDF file using a PDF viewer app\r\n                Intent intent = new Intent(Intent.ACTION_VIEW);\r\n                Uri pdfUri = FileProvider.getUriForFile(this, \"alsaeeddev.com.fileProvider\", file);\r\n                intent.setDataAndType(pdfUri, \"application\/pdf\");\r\n                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); \/\/ Grant read permissions\r\n\r\n                try {\r\n                    startActivity(intent); \/\/ Launch the PDF viewer activity\r\n                } catch (ActivityNotFoundException e) {\r\n                    \/\/ Handle the case where no PDF viewer app is available\r\n                    Toast.makeText(getApplicationContext(), \"No PDF viewer app found\", Toast.LENGTH_SHORT).show();\r\n                }\r\n\r\n                Toast.makeText(this, \"File saved in \" + file.getAbsolutePath(), Toast.LENGTH_SHORT).show();\r\n                pdfDocument.close();\r\n\r\n            }else {\r\n                etCustomerName.setError(\"Enter Name\");\r\n            }\r\n\r\n\r\n\r\n\r\n        });\r\n    }\r\n\r\n\r\n    private String getCurrentDate() {\r\n        \/\/ Get the current date\r\n        Calendar calendar = Calendar.getInstance();\r\n        int year = calendar.get(Calendar.YEAR);\r\n        int month = calendar.get(Calendar.MONTH) + 1; \/\/ Month is zero-based, so add 1\r\n        int day = calendar.get(Calendar.DAY_OF_MONTH);\r\n\r\n\/\/ Construct the date string\r\n        return year + \"-\" + month + \"-\" + day;\r\n\r\n    }\r\n\r\n\r\n    private String getCurrentTime() {\r\n        \/\/ Get the current time\r\n        Calendar calendar = Calendar.getInstance();\r\n        int hour = calendar.get(Calendar.HOUR_OF_DAY); \/\/ 24-hour format\r\n        int minute = calendar.get(Calendar.MINUTE);\r\n        int second = calendar.get(Calendar.SECOND);\r\n\r\n\/\/ Construct the time string\r\n        return hour + \":\" + minute + \":\" + second;\r\n    }\r\n\r\n\r\n    private String calculateTotalPerItem(double price, int quantity) {\r\n        double total = price * quantity;\r\n        totalPricePerItemList.add(total);\r\n        return String.valueOf(total);\r\n    }\r\n\r\n\r\n    private double calculateSubTotal() {\r\n        double subTotal = 0;\r\n        for (int i = 0; i &lt; totalPricePerItemList.size(); i++) {\r\n            subTotal += totalPricePerItemList.get(i);\r\n        }\r\n        return subTotal;\r\n    }\r\n\r\n\r\n    private double calculateTax() {\r\n\r\n        return calculateSubTotal() * 0.5;\r\n    }\r\n\r\n    @Override\r\n    protected void onResume() {\r\n        super.onResume();\r\n        barcodeView.resume();\r\n    }\r\n\r\n    @Override\r\n    protected void onPause() {\r\n        super.onPause();\r\n        yAxisForValue = 280;\r\n        totalPricePerItemList.clear();\r\n        barcodeView.pause();\r\n\r\n    }\r\n\r\n    @Override\r\n    protected void onStop() {\r\n        yAxisForValue = 280;\r\n        totalPricePerItemList.clear();\r\n        super.onStop();\r\n    }\r\n\r\n    @Override\r\n    protected void onDestroy() {\r\n        listItem.clear();\r\n        fullCodeList.clear();\r\n        super.onDestroy();\r\n    }\r\n}\r\n<\/code>&lt;\/pre<\/pre>\n<h4>2. MyAdapter.java<\/h4>\n<p>&nbsp;<\/p>\n<pre><code>\r\npublic class MyAdapter extends RecyclerView.Adapter {\r\n    private final List itemList;\r\n\r\n   private final Context context;\r\n  private final QuantityChangeListener listener;\r\n\r\n    public MyAdapter(Context context, List data, QuantityChangeListener listener) {\r\n        this.itemList = data;\r\n       this.listener = listener;\r\n       this.context = context;\r\n    }\r\n\r\n    @NonNull\r\n    @Override\r\n    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {\r\n        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_item, parent, false);\r\n        return new MyViewHolder(view);\r\n    }\r\n\r\n    @Override\r\n    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {\r\n        holder.bindData(position);\r\n\r\n      \/\/  holder.itemView.setOnClickListener(v -&gt; Toast.makeText(context, itemList.get(position).getItemQuantity(), Toast.LENGTH_SHORT).show());\r\n    }\r\n\r\n    @Override\r\n    public int getItemCount() {\r\n        return itemList.size();\r\n    }\r\n\r\n    public void addItem(String item) {\r\n      \/*  mData.add(item);\r\n        notifyItemInserted(mData.size() - 1);*\/\r\n\r\n     \/*   mData.add(0, item); \/\/ Insert item at index 0\r\n        notifyItemInserted(0);*\/\r\n    }\r\n\r\n    public  class MyViewHolder extends RecyclerView.ViewHolder {\r\n        TextView itemName, itemPrice;\r\n        EditText editText;\r\n\r\n\r\n        public MyViewHolder(@NonNull View itemView) {\r\n            super(itemView);\r\n            itemName = itemView.findViewById(R.id.tvItemName);\r\n            itemPrice = itemView.findViewById(R.id.tvItemPrice);\r\n            editText = itemView.findViewById(R.id.etQuantity);\r\n\r\n\r\n        }\r\n\r\n        public void bindData(int position) {\r\n            ItemModel item = itemList.get(position);\r\n            itemName.setText(item.getItemName());\r\n           itemPrice.setText(String.valueOf(item.getItemPrice()));\r\n           editText.setText(String.valueOf(item.getItemQuantity()));\r\n\r\n           editText.addTextChangedListener(new TextWatcher() {\r\n               @Override\r\n               public void beforeTextChanged(CharSequence s, int start, int count, int after) {\r\n\r\n               }\r\n\r\n               @Override\r\n               public void onTextChanged(CharSequence s, int start, int before, int count) {\r\n                   if(!TextUtils.isEmpty(s.toString())){\r\n                       int quantity = Integer.parseInt(s.toString());\r\n                       if(quantity != 0) {\r\n                           item.setItemQuantity(quantity);\r\n                           \/\/   if(listener != null &amp;&amp; position != RecyclerView.NO_POSITION) {\r\n                           listener.onQuantityChanged(position, quantity);\r\n                       }\r\n                     \/\/  }\r\n                   }\r\n               }\r\n\r\n               @Override\r\n               public void afterTextChanged(Editable s) {\r\n\r\n               }\r\n           });\r\n\r\n\r\n\r\n\r\n\r\n        }\r\n\r\n   \/*     public interface QuantityChangeListener {\r\n            void onQuantityChanged(int position, int quantity);\r\n        }\r\n\r\n        public void setListener(QuantityChangeListener listener){\r\n            listener = listener;\r\n        }*\/\r\n\r\n\r\n    }\r\n\r\n}\r\n<\/code>&lt;\/pre<\/pre>\n<h4>3. QuantityChangeListener.java<\/h4>\n<p>&nbsp;<\/p>\n<pre><code>\r\npublic interface QuantityChangeListener {\r\n    void onQuantityChanged(int position, int quantity);\r\n}\r\n<\/code>&lt;\/pre<\/pre>\n<h4>4. ItemModel.java<\/h4>\n<p>&nbsp;<\/p>\n<pre><code>\r\npublic class ItemModel {\r\n    private final double itemPrice;\r\n    private final String itemName;\r\n    private int itemQuantity;\r\n\r\n    public int getItemQuantity() {\r\n        return itemQuantity;\r\n    }\r\n\r\n    public void setItemQuantity(int quantity){\r\n        this.itemQuantity = quantity;\r\n    }\r\n\r\n\r\n\r\n    public double getItemPrice() {\r\n        return itemPrice;\r\n    }\r\n\r\n    public String getItemName() {\r\n        return itemName;\r\n    }\r\n\r\n\r\n    public ItemModel(double itemPrice, String itemName, int itemQuantity) {\r\n        this.itemPrice = itemPrice;\r\n        this.itemName = itemName;\r\n        this.itemQuantity = itemQuantity;\r\n    }\r\n\r\n\r\n\r\n\r\n}\r\n<\/code>&lt;\/pre<\/pre>\n<h4>5. activity_main.xml<\/h4>\n<p>&nbsp;<\/p>\n<pre><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;androidx.constraintlayout.widget.ConstraintLayout\r\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:elevation=\"10dp\"\r\n    android:id=\"@+id\/main\"\r\n    tools:context=\".MainActivity\"&gt;\r\n\r\n    &lt;androidx.recyclerview.widget.RecyclerView\r\n        android:id=\"@+id\/myRecyclerView\"\r\n        android:layout_width=\"0dp\"\r\n        android:layout_height=\"0dp\"\r\n        android:layout_marginStart=\"1dp\"\r\n        android:layout_marginTop=\"8dp\"\r\n        android:layout_marginEnd=\"1dp\"\r\n        app:layout_constraintBottom_toTopOf=\"@id\/btnNext\"\r\n        app:layout_constraintEnd_toEndOf=\"parent\"\r\n        app:layout_constraintStart_toStartOf=\"parent\"\r\n        android:layout_marginBottom=\"8dp\"\r\n        app:layout_constraintTop_toBottomOf=\"@+id\/zxingBarcodeScanner\" \/&gt;\r\n\r\n    &lt;com.journeyapps.barcodescanner.DecoratedBarcodeView\r\n        android:id=\"@+id\/zxingBarcodeScanner\"\r\n        android:layout_width=\"0dp\"\r\n        android:layout_height=\"150dp\"\r\n        android:layout_marginStart=\"8dp\"\r\n        android:layout_marginTop=\"8dp\"\r\n        android:layout_marginEnd=\"8dp\"\r\n        app:layout_constraintEnd_toEndOf=\"parent\"\r\n        app:layout_constraintStart_toStartOf=\"parent\"\r\n        app:layout_constraintTop_toBottomOf=\"@id\/etCustomerName\" \/&gt;\r\n\r\n \r\n\r\n    &lt;androidx.appcompat.widget.AppCompatButton\r\n        android:id=\"@+id\/btnNext\"\r\n        android:layout_width=\"200dp\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Generate Invoice\"\r\n        android:textAllCaps=\"false\"\r\n        android:background=\"@drawable\/btn_bg\"\r\n        app:layout_constraintBottom_toBottomOf=\"parent\"\r\n        app:layout_constraintEnd_toEndOf=\"parent\"\r\n        android:layout_marginBottom=\"8dp\"\r\n        app:layout_constraintStart_toStartOf=\"parent\" \/&gt;\r\n\r\n    &lt;EditText\r\n        android:id=\"@+id\/etCustomerName\"\r\n        android:layout_width=\"0dp\"\r\n        android:layout_height=\"48dp\"\r\n        android:layout_marginStart=\"8dp\"\r\n        android:layout_marginTop=\"8dp\"\r\n        android:layout_marginEnd=\"8dp\"\r\n        android:background=\"@drawable\/btn_bg\"\r\n        android:ems=\"10\"\r\n        android:textSize=\"14sp\"\r\n        android:paddingStart=\"8dp\"\r\n        android:paddingEnd=\"8dp\"\r\n        android:inputType=\"text\"\r\n        android:hint=\"Customer name\"\r\n        app:layout_constraintEnd_toEndOf=\"parent\"\r\n        app:layout_constraintStart_toStartOf=\"parent\"\r\n        app:layout_constraintTop_toTopOf=\"parent\" \/&gt;\r\n\r\n&lt;\/androidx.constraintlayout.widget.ConstraintLayout&gt;\r\n<\/code><\/pre>\n<h4>6. rv_item.xml<\/h4>\n<pre><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"wrap_content\"&gt;\r\n\r\n    &lt;androidx.cardview.widget.CardView\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        app:layout_constraintEnd_toEndOf=\"parent\"\r\n        app:layout_constraintStart_toStartOf=\"parent\"\r\n        android:layout_marginEnd=\"8dp\"\r\n        android:layout_marginStart=\"8dp\"\r\n        android:layout_marginTop=\"5dp\"\r\n        android:elevation=\"8dp\"\r\n        android:backgroundTint=\"#E7EFE6\"\r\n        app:cardCornerRadius=\"8dp\"\r\n        app:layout_constraintTop_toTopOf=\"parent\"&gt;\r\n\r\n        &lt;androidx.constraintlayout.widget.ConstraintLayout\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"match_parent\"&gt;\r\n\r\n            &lt;TextView\r\n                android:id=\"@+id\/tvItemName\"\r\n                android:layout_width=\"0dp\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:layout_marginStart=\"8dp\"\r\n                android:layout_marginTop=\"8dp\"\r\n                android:padding=\"3dp\"\r\n                android:text=\"Pepsi\"\r\n                android:textColor=\"@color\/black\"\r\n                android:textStyle=\"bold\"\r\n                app:layout_constraintEnd_toStartOf=\"@+id\/etQuantity\"\r\n                app:layout_constraintStart_toStartOf=\"parent\"\r\n                app:layout_constraintTop_toTopOf=\"parent\" \/&gt;\r\n\r\n            &lt;TextView\r\n                android:id=\"@+id\/tvItemPrice\"\r\n                android:layout_width=\"0dp\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:layout_marginEnd=\"8dp\"\r\n                android:layout_marginBottom=\"8dp\"\r\n                android:padding=\"3dp\"\r\n                android:text=\"$8\"\r\n                android:layout_marginTop=\"3dp\"\r\n                app:layout_constraintBottom_toBottomOf=\"parent\"\r\n                app:layout_constraintEnd_toEndOf=\"parent\"\r\n                app:layout_constraintTop_toBottomOf=\"@+id\/tvItemName\" \/&gt;\r\n\r\n            &lt;TextView\r\n                android:id=\"@+id\/textView\"\r\n                android:layout_width=\"0dp\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:layout_marginEnd=\"5dp\"\r\n                android:layout_marginBottom=\"8dp\"\r\n                android:padding=\"3dp\"\r\n                android:text=\"Price\"\r\n                android:layout_marginTop=\"3dp\"\r\n                app:layout_constraintBottom_toBottomOf=\"parent\"\r\n                app:layout_constraintEnd_toStartOf=\"@+id\/tvItemPrice\"\r\n                app:layout_constraintTop_toBottomOf=\"@+id\/tvItemName\" \/&gt;\r\n\r\n            &lt;EditText\r\n                android:id=\"@+id\/etQuantity\"\r\n                android:layout_width=\"0dp\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:background=\"@android:color\/transparent\"\r\n                android:text=\"1\"\r\n                android:layout_marginEnd=\"8dp\"\r\n                android:paddingStart=\"8dp\"\r\n                android:paddingEnd=\"8dp\"\r\n                android:ems=\"4\"\r\n                android:gravity=\"center\"\r\n                app:layout_constraintBottom_toBottomOf=\"@+id\/tvItemName\"\r\n                app:layout_constraintEnd_toEndOf=\"parent\"\r\n                app:layout_constraintTop_toTopOf=\"@+id\/tvItemName\" \/&gt;\r\n\r\n        &lt;\/androidx.constraintlayout.widget.ConstraintLayout&gt;\r\n\r\n    &lt;\/androidx.cardview.widget.CardView&gt;\r\n\r\n&lt;\/androidx.constraintlayout.widget.ConstraintLayout&gt;\r\n<\/code><\/pre>\n<hr \/>\n<p><iframe loading=\"lazy\" title=\"Barcode Scanner Invoice Generator App in Android Java | PDF Generator | Free Source Code #shorts\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/mVArINH1CXg?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<hr \/>\n<p><a href=\"https:\/\/github.com\/alsaeeddev\/InvoiceGenerator\/archive\/refs\/heads\/main.zip\">Download Source Code<\/a><\/p>\n<h2>Conclusion<\/h2>\n<p>By following these steps, you can build a functional Android application that scans barcodes, lists products in a <code>RecyclerView<\/code>, and generates a PDF invoice. This project is highly useful for businesses looking for an easy invoicing system within their Android app.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this tutorial, we will explore how to develop a Barcode Scanner Invoice Generator App in Android Java that allows users to scan barcodes, add products to a list, and generate a PDF invoice. This app is ideal for small businesses or retail stores that need a quick and efficient way to manage transactions. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3762,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,117,164],"tags":[],"class_list":["post-3647","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","category-java","category-source-codes"],"_links":{"self":[{"href":"https:\/\/alsaeeddev.com\/shop\/wp-json\/wp\/v2\/posts\/3647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alsaeeddev.com\/shop\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alsaeeddev.com\/shop\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alsaeeddev.com\/shop\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alsaeeddev.com\/shop\/wp-json\/wp\/v2\/comments?post=3647"}],"version-history":[{"count":20,"href":"https:\/\/alsaeeddev.com\/shop\/wp-json\/wp\/v2\/posts\/3647\/revisions"}],"predecessor-version":[{"id":3788,"href":"https:\/\/alsaeeddev.com\/shop\/wp-json\/wp\/v2\/posts\/3647\/revisions\/3788"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alsaeeddev.com\/shop\/wp-json\/wp\/v2\/media\/3762"}],"wp:attachment":[{"href":"https:\/\/alsaeeddev.com\/shop\/wp-json\/wp\/v2\/media?parent=3647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alsaeeddev.com\/shop\/wp-json\/wp\/v2\/categories?post=3647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alsaeeddev.com\/shop\/wp-json\/wp\/v2\/tags?post=3647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}