Android 프로그래밍에 새롭습니다.Android tablelayout보기가 표시되지 않습니다.
테이블로 서식이 지정된 목록 (데이터베이스의 항목 포함)을 추가하려는 레이아웃 XML이 있습니다. 이 레이아웃에 아무것도 추가하지 않습니다
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_cat);
DatabaseHandler db = new DatabaseHandler(this);
List<Category> allCategories = db.getAllCategories();
//Get the main layout from XML
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.edit_cat);
//Create table layout for the categories
TableLayout catList = new TableLayout(this);
//Iterate the categories, and organize in tables
for (Category category : allCategories) {
TableRow tr = new TableRow(this);
//Display category name
TextView name = new TextView(this);
name.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
name.setText(category.getName());
//Display category type
TextView type = new TextView(this);
type.setText(category.getType());
type.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
//Display edit button
Button btnEdit = new Button(this);
btnEdit.setText(getResources().getString(R.string.edit));
btnEdit.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
//Display delete button
Button btnDelete = new Button(this);
btnDelete.setText(getResources().getString(R.string.delete));
btnDelete.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(name);
tr.addView(type);
tr.addView(btnEdit);
tr.addView(btnDelete);
catList.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
mainLayout.addView(catList);
}
:
여기에 코드입니다. 이 아이디어가 효과가없는 이유는 무엇입니까?
편집 : 여기에 XML 코드를 추가 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/edit_cat"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView style="@style/pageHeader"
android:text="@string/catEditor"/>
<Button
android:id="@+id/btnNewCategory"
android:text="@string/newCategory"
android:textSize="11pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onBtnClicked"/>
<Button
android:id="@+id/back"
android:text="@string/back"
android:textSize="11pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onBtnClicked"/>
</LinearLayout>
모두 선택하십시오. 범주가 비어 있지 않습니까? 데이터베이스에서 데이터를 가져 오는 중입니까? – kosa
예, Log.v ('EditCat', category.getName())를 추가하고 문제없이 logCat에 목록을 가져 왔습니다. – LongInt
edit_cat.xml 레이아웃 설정을 확인하는 것이 좋습니다. – kosa