1

problem:

problem


if I fix:

if I fix


In datatest.csv, there are 10 lines data.
I want to add my list lines that I want.

In example, If categoryText = "에스프레소&라떼", list must be 2 lines.

나이트로 바닐라 크림,스타벅스,에스프레소&라떼,5900
프렌치 애플 타르트 나이트로,할리스,에스프레소&라떼,6000



datatest.csv:

나이트로 바닐라 크림,스타벅스,에스프레소&라떼,5900
콜드 브루 오트 라떼,스타벅스,콜드브루,5600
포레스트 콜드 브루,스타벅스,콜드브루,5900
나이트로 콜드 브루,스타벅스,콜드브루,5800
돌체 콜드 브루,스타벅스,콜드브루,5800
바닐라 크림 콜드 브루,스타벅스,콜드브루,5500
벨벳 다크 모카 나이트로,스타벅스,콜드브루,6000
콜드 브루,탐앤탐스,콜드브루,4500
콜드 브루 몰트,탐앤탐스,콜드브루,4500
콜드 브루 플로트,앤제리너스,콜드브루,4500
프렌치 애플 타르트 나이트로,할리스,에스프레소&라떼,6000


dataImage.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <array name = "starbucks_menu">
        <item>@drawable/nightro_vanila_cream</item>
        <item>@drawable/cold_brew_oat_latte</item>
        <item>@drawable/forest_cold_brew</item>
        <item>@drawable/nightro_cold_brew</item>
        <item>@drawable/dolche_cold_brew</item>
        <item>@drawable/vanila_cream_cold_brew</item>
        <item>@drawable/velvet_dark_mocha_nightro</item>
        <item>@drawable/cold_brew_malt</item>
        <item>@drawable/cold_brew_float</item>
        <item>@drawable/french_apple_tart_nightro</item>
    </array>
</resources>

viewpage() method in MainActivity.java:

private void viewpage(){
        Intent dataIntent = getIntent();
        String keyword;

        InputStream is = this.getResources().openRawResource(R.raw.datatest);
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        TypedArray typedArray = getResources().obtainTypedArray(R.array.starbucks_menu);
        list = new ArrayList<>();
        int i = 0;

        // 카테고리 데이터값 가져오기
        keyword = dataIntent.getStringExtra("카테고리명");
        resultText = (TextView) findViewById(R.id.resultText1);
        resultText.setText(keyword);

        try {
            String line;
            String categoryText = (String)resultText.getText();
            while ((line = reader.readLine()) != null && (i < typedArray.length())) {
                // do something with "line"
                String array[] = line.split(",");

                if(categoryText == array[2]) {
                    list.add(new DataPage(typedArray.getResourceId(i, -1), array[0], array[1], array[2], Integer.parseInt(array[3])));
                    i++;
                }else{
                    i++;
                }
            }
        }
        catch (IOException ex) {
            // handle exception
        }
        finally {
            try {
                is.close();
            }
            catch (IOException e) {
                // handle exception
            }
        }

I think i have to fix this code.

 if(categoryText == array[2]) {
                    list.add(new DataPage(typedArray.getResourceId(i, -1), array[0], array[1], array[2], Integer.parseInt(array[3])));
                    i++;
                }else{
                    i++;
                }


If you want to know more information, you can tell me anytime.

Ganada
  • 25
  • 1
  • 5

0 Answers0