이 코드를 작성하여 자산 폴더 (내 파일 이름 : book.xls)에 붙여 넣으면 Excel 파일을 읽을 수 있습니다. 하지만 버튼을 누르면 파일이 보이지 않고 아무 것도 보여주지 않습니다. 제 문제를 해결하도록 도와주세요. 고마워요. 여기 내 코드는 다음 display()
방법은 결코 당신의 내면의 for
루프로android.java에서 Excel 파일 읽기
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.android.readingexcellfile.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/textView" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="28dp"
android:layout_marginStart="28dp"
android:layout_marginTop="69dp"
android:onClick="order"
android:id="@+id/button" />
</RelativeLayout>
이 문제를 해결했으면 다음으로 고려해야 할 것은 "왜 Excel 파일입니까?"입니다. 파일이 자산 폴더에 임베드되어있어 사용자가 변경할 수없는 경우이를 .csv 파일과 같은보다 친숙한 형식으로 변환하거나 Java로 데이터 클래스를 만드는 것이 좋습니다. 이 데이터? 그런 다음 Excel 파일과 Jexcel 라이브러리를 모두 생략하면 APK를 훨씬 더 작게 만들 수 있습니다. – GreyBeardedGeek