android - Handle programmaticaly created spinners and locate them to bottom -
i developing app, can fill school shedule(with auth etc.) in dialog class create new spinner + textview. how allocate them in mainactivity , how set content view bottom of list? know there's layoutparams thing, can't understand it.
also great if can me remove items dialog window after choosing.
code:
public class othersubjectsdialog extends dialogfragment implements view.onclicklistener { public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { getdialog().settitle("title!"); view v = inflater.inflate(r.layout.dialog_layout, null); v.findviewbyid(r.id.btn_inf).setonclicklistener(this); v.findviewbyid(r.id.btn_phys).setonclicklistener(this); v.findviewbyid(r.id.btn_soc).setonclicklistener(this); v.findviewbyid(r.id.btn_chem).setonclicklistener(this); v.findviewbyid(r.id.btn_biol).setonclicklistener(this); return v; } @targetapi(build.version_codes.m) public void onclick(view v) { relativelayout.layoutparams lp = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content, relativelayout.layoutparams.wrap_content); lp.alignwithparent = true; spinner spinner = new spinner(super.getcontext()); arrayadapter<?> adapter = null; textview textview = new textview(super.getcontext()); switch (v.getid()) { case r.id.btn_inf: adapter = arrayadapter.createfromresource(super.getcontext(), r.array.inf_groups_array, android.r.layout.simple_spinner_item); adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); textview.settext("Группа по информатике:"); break; case r.id.btn_phys: adapter = arrayadapter.createfromresource(super.getcontext(), r.array.phys_groups_array, android.r.layout.simple_spinner_item); adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); textview.settext("Группа по физике:"); break; case r.id.btn_soc: adapter = arrayadapter.createfromresource(super.getcontext(), r.array.soc_groups_array, android.r.layout.simple_spinner_item); adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); textview.settext("Группа по обществознанию:"); break; case r.id.btn_chem: adapter = arrayadapter.createfromresource(super.getcontext(), r.array.chem_groups_array, android.r.layout.simple_spinner_item); adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); textview.settext("Группа по химии:"); break; case r.id.btn_biol: adapter = arrayadapter.createfromresource(super.getcontext(), r.array.biol_groups_array, android.r.layout.simple_spinner_item); adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); textview.settext("Группа по биологии:"); break; } spinner.setadapter(adapter); super.getactivity().addcontentview(textview, lp); super.getactivity().addcontentview(spinner, lp); dismiss(); } public void ondismiss(dialoginterface dialog) { super.ondismiss(dialog); } public void oncancel(dialoginterface dialog) { super.oncancel(dialog); }
}
dialog fragment xml:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical"> <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="20dp" android:text="Выберите дополнительный предмет:" android:textappearance="?android:attr/textappearancelarge"> </textview> <tablelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/inf" android:id="@+id/btn_inf" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/phys" android:id="@+id/btn_phys" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/soc" android:id="@+id/btn_soc" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/chem" android:id="@+id/btn_chem" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/biol" android:id="@+id/btn_biol" /> </tablelayout> </linearlayout>
try spinner position:
super.getactivity().addcontentview(textview, lp); lp.addrule(relativelayout.align_parent_bottom); super.getactivity().addcontentview(spinner, lp);
Comments
Post a Comment