【问题标题】:show dialogbox from item litsview and edittext从项目 litsview 和 edittext 显示对话框
【发布时间】:2013-07-16 08:23:35
【问题描述】:

请帮助我。基本上我希望当用户单击列表视图中的项目时弹出/对话框。 DialogBox 包括edittext 和item listview。谢谢

这是我的代码 MainActivity.class,用于显示 toast。

setContentView(R.layout.activity_main);
        initialize();

        btnkl.setOnClickListener(this);
        btnhps.setOnClickListener(this);

        lv = (ListView)findViewById(R.id.listView1);

        String[] satu = getResources().getStringArray(R.array.quotes);      
        lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, satu));
        lv.setOnItemClickListener(this);

@Override
    public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
                Toast.LENGTH_LONG).show();      
    }

【问题讨论】:

  • 是所有列表项的 Dailog 框......
  • 不一样,对话框只显示在项目点击

标签: android listview android-edittext dialog


【解决方案1】:

Android Developer: Dialogs有详细的对话框使用教程

最简单的方法是使用自定义布局构建一个 AlertDialog,它显示您想要的 ListView 和 EditText。

// 1. Instantiate an AlertDialog.Builder with its constructor
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

// 2. Chain together various setter methods to set the dialog characteristics
builder.setMessage(R.string.dialog_message)
       .setTitle(R.string.dialog_title)

//Use your custom layout (f.e. by findViewByID(custom_dialog_layout));
.setView(custumLayout);

// 3. Get the AlertDialog from create()
AlertDialog dialog = builder.create();

【讨论】:

  • 您能否向您的代码展示有关我的案例的更多详细信息。谢谢
【解决方案2】:

如果您对所有列表项使用相同的 Dailog,那么,

您只需在 OnItemClick Listner 中创建进度 Dailog。然后创建一个包含 edittext 和您的列表项(根据您的要求)的 xml(布局)文件,然后使用 setcontentview 方法将此文件设置为您的对话框。下面就是例子。

   Dialog dialog=new Dialog(context);
   dialogSort.requestWindowFeature(Window.FEATURE_NO_TITLE);
   dialog.setContentView(R.layout.dialog_sort);
   dialog.show();  

【讨论】:

  • 最终对话框 about = new Dialog(context); about.setContentView(R.layout.activity_about); about.setTitle("关于"); TextView text = (TextView) about.findViewById(R.id.textdialogresoult); text.setText("TextView") // 我想从 EditText Input 中获取文本
猜你喜欢
  • 2016-06-21
  • 1970-01-01
  • 2018-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多