我有一个TO-DO List,并且有一个AlertDialog可以将项目添加到ListView。 在每个项目上有一个Button(id:button1),当我点击Button想要一个AlertDialog来apper。 我尝试了不同的代码,但我无法弄清楚如何做到这一点。
这是我的代码......
button1 = (Button) findViewById(R.id.button1); dialog = new AlertDialog.Builder(MainActivity.this).create(); dialog.setMessage("New list name"); dialog.setButton("Rename", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); dialog.setButton2("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton3("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.show(); } });所以我想要更多的Button来显示AlertDialog。
请帮忙。
I have a TO-DO List and there is an AlertDialog that adds items to the ListView. On each item there is a Button (id: button1) when I click on the Button want a AlertDialog to apper. I have tried Different codes but i have not been able to figer out how to do it.
this is my code...
button1 = (Button) findViewById(R.id.button1); dialog = new AlertDialog.Builder(MainActivity.this).create(); dialog.setMessage("New list name"); dialog.setButton("Rename", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); dialog.setButton2("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton3("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.show(); } });So I want the more Button to make an AlertDialog appear.
Please Help.
最满意答案
你正试图在listitem中实现一个可点击的按钮wiah也是一个可点击的区域,android与它混淆,请阅读这个很好的教程;)
http://wiresareobsolete.com/wordpress/2011/08/clickable-zones-in-listview-items/
另一方面,如果单击按钮,问题实际上是显示对话框,请确保调用dialog.show(); 最后 ;)
You are trying to implement a clickable button inside a listitem wiah is also a clickable area, android gets confused with it, please read this nice tutorial ;)
http://wiresareobsolete.com/wordpress/2011/08/clickable-zones-in-listview-items/
If, on the other hand the button is getting clicked, and the problem is actually in showing the dialog please make sure that you call dialog.show(); at the end ;)
AlertDialog不适用(The AlertDialog does not apper)我有一个TO-DO List,并且有一个AlertDialog可以将项目添加到ListView。 在每个项目上有一个Button(id:button1),当我点击Button想要一个AlertDialog来apper。 我尝试了不同的代码,但我无法弄清楚如何做到这一点。
这是我的代码......
button1 = (Button) findViewById(R.id.button1); dialog = new AlertDialog.Builder(MainActivity.this).create(); dialog.setMessage("New list name"); dialog.setButton("Rename", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); dialog.setButton2("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton3("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.show(); } });所以我想要更多的Button来显示AlertDialog。
请帮忙。
I have a TO-DO List and there is an AlertDialog that adds items to the ListView. On each item there is a Button (id: button1) when I click on the Button want a AlertDialog to apper. I have tried Different codes but i have not been able to figer out how to do it.
this is my code...
button1 = (Button) findViewById(R.id.button1); dialog = new AlertDialog.Builder(MainActivity.this).create(); dialog.setMessage("New list name"); dialog.setButton("Rename", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); dialog.setButton2("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton3("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.show(); } });So I want the more Button to make an AlertDialog appear.
Please Help.
最满意答案
你正试图在listitem中实现一个可点击的按钮wiah也是一个可点击的区域,android与它混淆,请阅读这个很好的教程;)
http://wiresareobsolete.com/wordpress/2011/08/clickable-zones-in-listview-items/
另一方面,如果单击按钮,问题实际上是显示对话框,请确保调用dialog.show(); 最后 ;)
You are trying to implement a clickable button inside a listitem wiah is also a clickable area, android gets confused with it, please read this nice tutorial ;)
http://wiresareobsolete.com/wordpress/2011/08/clickable-zones-in-listview-items/
If, on the other hand the button is getting clicked, and the problem is actually in showing the dialog please make sure that you call dialog.show(); at the end ;)
发布评论