나는 나의 테이블 레이아웃 스크롤하기 위해 내 상대 레이아웃의 스크롤 뷰를 작성하려하지만 난이 오류가 점점 계속 :만들기 테이블 행은
02-02 19:29:10.116: E/AndroidRuntime(9400):
java.lang.RuntimeException: Unable to start activity ComponentInfo{test.com.classmanagertest/test.com.classmanagertest.StudentsMasterList}: java.lang.IllegalStateException:
The specified child already has a parent. You must call removeView() on the child's parent first.
이것은이다 내 표 레이아웃이 데이터베이스에 디스플레이의 필드 :
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.students_masterlist);
db=openOrCreateDatabase("ClassManager",MODE_WORLD_WRITEABLE, null);
Cursor c=db.rawQuery("SELECT StudPic, StudentID, LastName FROM MasterStudents", null);
int count= c.getCount();
c.moveToFirst();
TableLayout tableLayout = new TableLayout(getApplicationContext());
tableLayout.setVerticalScrollBarEnabled(true);
TableRow tableRow;
TextView textView, textView1;
ImageView StudImageView;
RelativeLayout rl=(RelativeLayout)findViewById(R.id.layout);
ScrollView sv = new ScrollView(this);
sv.addView(tableLayout);
rl.addView(sv);
for (Integer j = 0; j < count; j++)
{
tableRow = new TableRow(getApplicationContext());
StudImageView = new ImageView(getApplicationContext());
StudImageView.setPadding(20, 20, 20, 20);
StudImage=c.getBlob(c.getColumnIndex("StudPic"));
Bitmap b1= BitmapFactory.decodeByteArray(StudImage, 0, StudImage.length);
StudImageView.setImageBitmap(b1);
tableRow.addView(StudImageView);
textView1 = new TextView(getApplicationContext());
textView1.setText(c.getString(c.getColumnIndex("StudentID")));
textView1.setPadding(20, 20, 20, 20);
textView1.setTextColor(getResources().getColor(R.color.blueactionbar));
textView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP,25);
textView1.setTypeface(null, Typeface.BOLD);
tableRow.addView(textView1);
textView = new TextView(getApplicationContext());
textView.setText(c.getString(c.getColumnIndex("LastName")));
textView.setPadding(20, 20, 20, 20);
textView.setTextColor(getResources().getColor(R.color.blueactionbar));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP,25);
textView.setTypeface(null, Typeface.BOLD);
tableRow.addView(textView);
tableLayout.addView(tableRow);
c.moveToNext() ;
}
setContentView(tableLayout);
db.close();
}
이 내 XML 파일입니다
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:layout_gravity="center_horizontal"
android:scrollbars="vertical|horizontal"
android:id="@+id/layout">
</RelativeLayout>
가 어떻게이 오류를 수정합니까?
도움을 주시면 감사하겠습니다. 정말 고맙습니다!
콘텐츠보기를 두 번 설정하는 이유는 무엇입니까? 그리고 테이블보기는 스크롤보기 (하위보기)에서 자식입니다 (또한 콘텐츠보기를 두 번째로 설정하는 경우). 이것은 – Droidekas
코드를 작성하는 잘못된 방법입니다. 그래서 첫 번째 setcontentview를 제거 하시겠습니까? – Kreyah
예 그리고 전체보기를 새로 고쳐야합니다. 이렇게하면,'requestLayout()'이라고 부르는 모든 행을 추가하면 – Droidekas