0

T User scans a receipt and the output is put in an editable Text, which the User can adjust if the OCR made a mistake.

I have a "confirm" button, on which the data from these editable Text fields should be taken and put into a new fragment called "History" which is supposed to be a table that simply stores the data for every new receipt that is scanned. With 3 simple rows "Total","Data","Store".

How to implement this functionality?

This is how it looks when you use the OCRTHis is what i want later in the History Tab

The code for my MainActivity which sets up the TabBar: class MainActivity : AppCompatActivity() {

private lateinit var viewPager: ViewPager
private lateinit var tabs: TabLayout

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    viewPager = findViewById(R.id.viewPager)
    tabs = findViewById(R.id.tabs)
    setUpTabs()
}

private fun setUpTabs(){
    val adapter = ViewPagerAdapter(supportFragmentManager)
    adapter.addFragment(HomeFragment(),"")
    adapter.addFragment(HistoryFragment(),"")
    adapter.addFragment(Scanner(),"")
    viewPager.adapter = adapter
    tabs.setupWithViewPager(viewPager)
    tabs.getTabAt(0)!!.setIcon(R.drawable.ic_baseline_home_24)
    tabs.getTabAt(1)!!.setIcon(R.drawable.ic_baseline_show_chart_24)
    tabs.getTabAt(2)!!.setIcon(R.drawable.ic_baseline_receipt_24)
}

In my fragment for the OCR this is the code for the Textrecognition and putting it in the TextView:

   private fun textRecognitionAction() {

    var text = ""
    receiptsViewModel.textDetector.process(mlkitImage)
        .addOnSuccessListener {
            pb.visibility = View.GONE
            for (block in it.textBlocks) text += block.text + "\n"
            val receipts = receiptsViewModel.getReceipts(text)
            editTotal.setText(receipts.total, TextView.BufferType.EDITABLE)
            editStore.setText(receipts.store, TextView.BufferType.EDITABLE)
            editDate.setText(receipts.date, TextView.BufferType.EDITABLE)

        }
}
dkiwikid
  • 95
  • 1
  • 9
  • Are you using navigation component? Could you put some code so we know what are you using and how to help? – Skizo-ozᴉʞS ツ Jun 11 '21 at 07:30
  • @Skizo-ozᴉʞS I just addet some code, not sure what code exacly is needed since im completly new to programming. I don't use a navigation component, I just set up a TabBar in my Activity and use it to navigate between fragments. – dkiwikid Jun 11 '21 at 09:37

0 Answers0