带有ListView适配器的AlertDialog

时间:2018-02-12 15:30:45

标签: android alertdialog listadapter listview-adapter

我尝试使用ListView(适配器)执行AlertDialog,我得到警报对话框,但我没有得到ListView,所以我的代码是:

    public void namesDialog(View view){
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.list_view_names_dialog, null);
    builder.setTitle("Names:");
    builder.setView(v);
    final ListAdapterDetailsNames adapter = new ListAdapterDetailsNames(this, mNames.getNames());
    mListViewTextNames.setAdapter(adapter);
    AlertDialog dialog = builder.create();
    dialog.show();

}

我应该怎样做才能在AlertDialog中获取listView?

非常感谢你的帮助:)

1 个答案:

答案 0 :(得分:0)

什么是myEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (et_change) { et_change = false; return; } et_change = true; String s = FormatHelper.toPersianNumber(charSequence.toString()); myEditText.setText(s); } @Override public void afterTextChanged(Editable s) { } }); ?您将适配器设置为甚至在您膨胀mListViewTextNames之前似乎存在的视图...您几乎肯定需要在膨胀的视图中R.layout.list_view_names_dialog以获得正确的findViewById()来设置适配器打开。