0
나는 활동에서 꼬리표가있는 listview가 있습니다. 내가하고 싶은 일은 footer에 textview를 프로그래밍 방식으로 추가하는 것입니다.안드로이드에서보기를 동적으로 추가하는 방법
LinearLayout layout = (LinearLayout)View.inflate(this, R.layout.footer, null);
TextView tv = new TextView(this);
tv.setText("added text");
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
tv.setVisibility(View.VISIBLE);
layout.addView(tv);
View footer = getLayoutInflater().inflate(R.layout.refer_footer, null, false);
listView.addFooterView(footer);
listView.setAdapter(adapter);
Activity.xml :
는 Activity.java, Activity.xml, footer.xml Activty.java의에서 onCreate의
부() 메소드 있습니다
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <ListView android:id="@+id/referList" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout>
footer.xml :
<LinearLayout
android:id="@+id/footer_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
xmlns:android="http://schemas.android.com/apk/res/android">
</LinearLayout>
하지만 app에 textview가 추가되지 않았습니다. 누군가 제발 도와주세요.
, 그리고'당신은 당신이 listView.addFooterView (바닥 글)'를 호출하기 때문에 관계가 게시 footer.xml',이'R.layout.refer_footer'으로' 형세. – njzk2