我没有收到任何错误,但项目没有动态显示.
请建议一种方法.
这是我的类和xml文件:
public class AlertDialogFragment extends DialogFragment {@OverrIDepublic Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenIEnt dialog construction AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); VIEw vIEw = inflater.inflate(R.layout.dialog,null); Spinner spin; spin = (Spinner)vIEw.findVIEwByID(R.ID.spinner1); List<String> List = new ArrayList<String>(); List.add("Material 1"); List.add("Material 2"); List.add("Material 3"); List.add("Material 4"); List.add("Material 5"); List.add("Material 6"); //Second List List<String> List2 = new ArrayList<String>(); List2.add("Mat 7"); List2.add("Mat 8"); List2.add("Mat 9"); //Combined List List<String> ListCombine = new ArrayList<String>(); ListCombine.addAll(List); ListCombine.addAll(List2); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(),androID.R.layout.simple_spinner_item,ListCombine); dataAdapter.setDropDownVIEwResource(androID.R.layout.simple_spinner_dropdown_item); spin.setAdapter(dataAdapter); builder .setTitle("Title") .setVIEw(inflater.inflate(R.layout.dialog,null)) .setPositivebutton("Add",new DialogInterface.OnClickListener() { public voID onClick(DialogInterface dialog,int ID) { // FIRE ZE MISSILES! } }) .setNegativebutton("Cancel",int ID) { // User cancelled the dialog } }); // Create the AlertDialog object and return it return builder.create();}
}
我的xml文件是:
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:orIEntation="vertical"androID:layout_wIDth="wrap_content"androID:layout_height="wrap_content"><linearLayout androID:orIEntation="horizontal" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_margin="20dp"><TextVIEw androID:ID="@+ID/textVIEw1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="Materials" androID:layout_marginRight="10dp" androID:textSize="20sp" androID:textAppearance="?androID:attr/textAppearanceMedium" /><Spinner androID:ID="@+ID/spinner1" androID:layout_wIDth="0dip" androID:layout_height="35dp" androID:layout_weight="1" androID:layout_marginRight="10dp" androID:background="#FFB2B2" /></linearLayout><linearLayout androID:orIEntation="horizontal" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_margin="20dp"><TextVIEw androID:ID="@+ID/textVIEw1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="Weight" androID:layout_marginRight="35dp" androID:textSize="20sp" androID:textAppearance="?androID:attr/textAppearanceMedium" /> <TextVIEw androID:ID="@+ID/textVIEw1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="55" androID:textSize="20sp" androID:textAppearance="?androID:attr/textAppearanceMedium" /></linearLayout>解决方法 而不是在这里膨胀第二个布局:
builder .setTitle("Title") .setVIEw(inflater.inflate(R.layout.dialog,null)) // Second layout!
只需使用已经膨胀和设置的布局:
builder .setTitle("Title") .setVIEw(vIEw) // Existing layout总结
以上是内存溢出为你收集整理的android – 在DialogFragment中动态添加微调器全部内容,希望文章能够帮你解决android – 在DialogFragment中动态添加微调器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)