0
Android 2.2를 사용하는 에뮬레이터에서 코드를 실행 중이므로 정상적으로 작동합니다. 하지만 내 장치 (Galaxy S 2.3.3)에 올려 놓으면 테이블의 요소 목록을 표시하는 기본 화면이 공백으로 남습니다. 그러나 토스트가 표시되며 app_name이있는 머리글TableLayout은 에뮬레이터에서는 정상적으로 보이지만 기기에서는 그렇지 않습니다.
이 테이블은 버튼 (XML로 정의 됨)과 DB에서로드 된 요소 목록으로 구성됩니다.
여기에 코드
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout android:id="@+id/TableLayoutMain"
android:layout_width="match_parent" android:layout_height="wrap_content">
<TableRow>
<Button android:text="@string/add_button" android:id="@+id/add_button"
android:layout_height="wrap_content" android:layout_marginTop="10dp"
android:layout_marginBottom="10dp" android:layout_width="match_parent"
android:layout_weight="1"></Button>
</TableRow>
</TableLayout>
</ScrollView>
그리고 main.xml에
: 나는 XML 정의와 프로그래밍 방식으로 추가 요소 간의 혼합이 작동하면 것인지 확실하지 않았다public void showList(Cursor c){
setContentView(R.layout.main);
table = (TableLayout) findViewById(R.id.TableLayoutMain);
do {
TableRow tr = new TableRow(this);
final int id = c.getInt(c.getColumnIndex(DatabaseAdapter.KEY_ROWID));
tr.setId(id);
tr.setBackgroundColor(ROW_COLOR);
tr.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
//do stuff
return true;
}
});
tr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do other stuff
}
});
TextView txt = getText(active, id, name);
tr.addView(txt);
table.addView(tr);
} while (c.moveToNext());
c.close();
}
. 그러나 나는 다양한 조합을 시도해 보았고 둘 다 똑같이 나쁘다고 말할 수 있습니다. 즉 에뮬레이터에서는 문제가없고 장치에 문제가 있습니다. 나는 또한 안드로이드 버전이 아닐 수 있다고 생각합니다. 이견있는 사람?
"ROW_COLOR"의 선언은 어디에 있습니까? – lv0gun9
죄송합니다, 언급하는 것을 잊어 버렸습니다 : 그것은 클래스에서 선언 된 상수입니다. – hansdampf