0
조각이 하나 있습니다.이 레이아웃은 하나의 버튼입니다.onClick을 사용하여 조각의 LinearLayout에 뷰를 추가하는 방법은 무엇입니까?
버튼을 클릭하면 textview_container에 textview가 추가됩니다.
?
myfragment.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:background="#00000000"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/textview_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:orientation="horizontal" >
</LinearLayout>
<Button
android:id="@+id/postbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:text="@string/edit"
android:textColor="@color/black"
android:textSize="14sp" />
</LinearLayout>
Myfragment.java
public class AlbumListDetailFragment extends Fragment implements OnClickListener {
Button postButton
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.myfragment , container, false);
}
public void onStart() {
super.onStart();
initViews();
}
private void initViews() {
button = (Button) getView().findViewById(R.id.postbutton);
button.setOnClickListner{new View.onClickListener(){
public void onClick(View v) {
//make and Textview into textview_container
}
}
}
}
당신이 컨테이너를 참조하는 텍스트 뷰를 생성하고 컨테이너에 추가해야합니다. – gpasci