불필요한 텍스트 제거하기

OCR을 이용해 식품성분표에서 추출한 텍스트에서 불필요한 부분을 잘라내는 과정

텍스트 제거 시행착오

텍스트 제거 해결

리사이클러뷰

아래 링크를 보고 따라해 보았다.

[Android Java] RecyclerView를 사용하여 목록 만들기

<aside> ⚠️ 문제점1. 북마크를 해제했을 때 사라지게 하는 기능을 넣어야한다. 문제점2. 식당 이름과 주소를 DB로부터 연동해서 보여주고, 북마크 된 상태를 저장해야한다.

</aside>

package com.example.listview;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private RecyclerView mRecyclerView;
    private MyRecyclerAdapter mRecyclerAdapter;
    private ArrayList<restaurantItem> mrestaurantItems;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mRecyclerView = (RecyclerView)findViewById(R.id.mRecyclerView);
        mRecyclerAdapter = new MyRecyclerAdapter();

        mRecyclerView.setAdapter(mRecyclerAdapter);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

        /* adapt data */
        mrestaurantItems = new ArrayList<>();
        for(int i=1;i<=10;i++){
            if(i%2==0)
                mrestaurantItems.add(new restaurantItem(true,i+"번째 식당",i+"번째 주소"));
            else
                mrestaurantItems.add(new restaurantItem(true,i+"번째 식당",i+"번째 주소"));

        }
        mRecyclerAdapter.setmRestList(mrestaurantItems);
    }
}
package com.example.listview;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;

public class MyRecyclerAdapter extends RecyclerView.Adapter<MyRecyclerAdapter.ViewHolder> {
    private ArrayList<restaurantItem> mRestList;

    @NonNull
    @Override
    public MyRecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout, parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyRecyclerAdapter.ViewHolder holder, int position) {
        holder.onBind(mRestList.get(position));
    }

    public void setmRestList(ArrayList<restaurantItem> list){
        this.mRestList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mRestList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        CheckBox star;
        TextView name;
        TextView address;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);

            star = (CheckBox) itemView.findViewById(R.id.star);
            name = (TextView) itemView.findViewById(R.id.name);
            address = (TextView) itemView.findViewById(R.id.address);
        }

        void onBind(restaurantItem item){
            star.setChecked(item.getStar());
            name.setText(item.getName());
            address.setText(item.getAddress());
        }
    }
}
package com.example.listview;

public class restaurantItem {
    String name;
    String address;
    boolean star;

    public String getName() {
        return name;
    }

    public String getAddress() {
        return address;
    }

    public boolean getStar() {
        return star;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setStar(boolean star) {
        this.star = star;
    }

    public restaurantItem(boolean star, String name, String address) {
        this.name = name;
        this.address = address;
        this.star = star;
    }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="<http://schemas.android.com/apk/res/android>"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:padding="20dp">

        <CheckBox
            android:id="@+id/star"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:button="@null"
            android:background="@drawable/custom_checkbox"/>

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:text="채식식당"
            android:textSize="16sp"
            android:textColor="#000"/>

        <TextView
            android:id="@+id/address"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="80dp"
            android:text="서울시 도봉구 쌍문동"
            android:textSize="12sp"
            android:textColor="#444"
            android:maxLines="1"/>

    </LinearLayout>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
    xmlns:app="<http://schemas.android.com/apk/res-auto>"
    xmlns:tools="<http://schemas.android.com/tools>"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/mRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbarFadeDuration="0"
        android:scrollbarSize="5dp"
        android:scrollbarThumbVertical="@android:color/darker_gray"
        android:scrollbars="vertical">
    </androidx.recyclerview.widget.RecyclerView
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="<http://schemas.android.com/apk/res/android>">
    <!-- 체크박스 해제 상태 -->
    <item android:state_checked="false"
        android:drawable="@android:drawable/star_off"/>
    <!-- 체크박스 선택 상태 -->
    <item android:state_checked="true"
        android:drawable="@android:drawable/star_on"/>
</selector>

Android Emulator - ListView 2022-04-19 16-42-53.mp4