gpt4 book ai didi

android - ListView 下方有额外空间的 DialogFragment

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:52:05 28 4
gpt4 key购买 nike

如您所见,在我的 ListView 底部列表元素下方,有多余的空间我似乎无法摆脱。我已经尝试过 Relative 和 Linearlayout,它们看起来都是这样的。这是代码: enter image description here

public class ChooseDialog extends DialogFragment implements
DialogInterface.OnClickListener {

String URLhome;
String Title;
String type;

/* public static ChooseDialog newInstance() {
ChooseDialog dialog = new ChooseDialog();
Log.v("a", "shit runs");
Bundle bundle = new Bundle();
dialog.setArguments(bundle);
return dialog;
}*/

public ChooseDialog(String type) {
this.type = type;
}

@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setCancelable(true);
int style = DialogFragment.STYLE_NORMAL, theme = 0;
setStyle(style, theme);
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(type);
builder.setNegativeButton("Cancel", this);
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogLayout = inflater.inflate(R.layout.dialog, null);
builder.setView(dialogLayout);

final String[] items = {"Red", "Green", "Blue" };

builder.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, items),
new DialogInterface.OnClickListener() {


public void onClick(DialogInterface dialog, int which) {
Log.v("touched: ", items[which].toString());

}}
);


return builder.create();

}

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub

}

}

以及启动对话框的代码:

public OnClickListener listener = new OnClickListener() {
public void onClick(View v) {
showNationalityDialog();
}
};

private void showNationalityDialog() {
FragmentManager fm = getSupportFragmentManager();
ChooseDialog nationalityDialog = new ChooseDialog("Nationality");

nationalityDialog.show(fm, "fragment_edit_name");
}

最佳答案

我知道这个问题从来没有引起太多关注,但我终于解决了这个问题。

通过使用我在 XML 中创建的 ListView 而不是设置构建器的适配器,我设法摆脱了所有多余的空间。

这是新代码的样子:

    switch (editText.getId()) {
case (0) :
ListView list = (ListView) dialogLayout.findViewById(R.id.listView1);
list.setAdapter(new ArrayAdapter<String>(activity, R.layout.dialoglist,
activity.getResources().getStringArray(R.array.ageArray)));
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
editText.setText(activity.getResources().getStringArray(R.array.ageArray)[arg2]);
dismiss();
}
});
builder = (Integer.parseInt(android.os.Build.VERSION.SDK) < 11)? new AlertDialog.Builder(activity) :
new AlertDialog.Builder(activity, android.R.style.Theme_Translucent);
builder.setNegativeButton("Cancel", this);
builder.setView(dialogLayout);

return builder.create();

关于android - ListView 下方有额外空间的 DialogFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10761754/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com