나는 안드로이드 애플 리케이션에서 sqlite의 내용을 보여줘야하는 안드로이드 애플리케이션을 만들고 있습니다.Dynamic TableLayout 안드로이드
그래서 여기 TableLayout을 사용하기로 결정했습니다.하지만 요점은 sqlite 데이터베이스의 열과 행이 이전에 결정되지 않았기 때문에 동적 열과 행을 처리하는 레이아웃 유형을 만들어야한다는 것입니다. 그래서 여기에 내가 뭐하는 거지
내가 레이아웃을 sublayout.xml, cells.xml, mainlayout.xml을 만든 것입니다. 이 레이아웃sublayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/subLayout_" >
</LinearLayout>
동적으로 cells.xml를 사용하여 셀을 추가하고있다.
cells.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/cell_"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cell"
android:textSize="25dp"/>
</LinearLayout>
그리고 내 하나 개의 행이 준비가 되 때 단순히 mainlayout.xml에 추가.
mainlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/tableLayout_"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"></LinearLayout>
</TableRow>
</TableLayout>
하지만 난 여기 nullpointer 예외를 얻고있다.
여기 내 수업 코드입니다.
LinearLayout layout,subLayout_;
layout=(LinearLayout)findViewById(R.id.tableLayout_);
subLayout_=(LinearLayout)findViewById(R.id.subLayout_);
for (int i = 0; i < columns.length; i++) {
Log.e("Column name", ""+columns[i]);
View v=inflater.inflate(R.layout.cells, null);
TextView tv=(TextView)v.findViewById(R.id.cell_);
tv.setText(columns[i]);
subLayout_.addView(v);
}
layout.addView(subLayout_);
내가 여기서 잘못하고있는 것을 도와 주시겠습니까?