如何使用OnItemLongClickListener覆盖OnItemClickListener(How to override OnItemClickListener with OnItemLongClickListener)
我在列表视图的活动中有OnItemClickListener,其中我开始另一个活动,我也有OnItemLongClickListener,其中我基本上想要删除长按行。当我点击列表视图OnItemClickListener工作正常,但当我长时间点击列表仍然是OnItemClickListener和OnItemLongClickListener.And我不希望OnItemClickListener工作时,我点击长。 这就是我的代码的样子。
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(MainActivity.this, CompleteInformationActivity.class); intent.putExtra("position", "" + selected.get(position)); startActivity(intent); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(MainActivity.this, "Long click happened.", Toast.LENGTH_SHORT).show(); adapter.notifyDataSetChanged(); final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("Do you want to delete?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "Item is Deleted.", Toast.LENGTH_SHORT).show(); } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "Item is not Deleted.", Toast.LENGTH_SHORT).show(); } }); AlertDialog dialog = builder.create(); dialog.show(); return false; } });
I have OnItemClickListener in my activity for list view in which i start another activity,and i also have OnItemLongClickListener in which basically i want to delete the long clicked row.When i click on list view OnItemClickListener works fine,but when when i long click on list still both OnItemClickListener and OnItemLongClickListener.And i don't want OnItemClickListener to work when i click long. This is how my code looks like.
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(MainActivity.this, CompleteInformationActivity.class); intent.putExtra("position", "" + selected.get(position)); startActivity(intent); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(MainActivity.this, "Long click happened.", Toast.LENGTH_SHORT).show(); adapter.notifyDataSetChanged(); final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("Do you want to delete?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "Item is Deleted.", Toast.LENGTH_SHORT).show(); } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "Item is not Deleted.", Toast.LENGTH_SHORT).show(); } }); AlertDialog dialog = builder.create(); dialog.show(); return false; } });
原文:https://stackoverflow.com/questions/33107829
最满意答案
尝试:
$productsChildren = Mage::getModel('catalog/category')->getCategories(3,0,false,true,false); $productsChildren->addAttributeToSelect('category_subtitle') ->addAttributeToSelect('category_slidertext');
如果
$productsChildren
是类别集合的实例,那将会有效。Try:
$productsChildren = Mage::getModel('catalog/category')->getCategories(3,0,false,true,false); $productsChildren->addAttributeToSelect('category_subtitle') ->addAttributeToSelect('category_slidertext');
That will work if
$productsChildren
is an instance of the category collection.
相关问答
更多-
你可以这样试试。 $category = Mage::registry('current_category'); getFooterText()) : ?> categoryAttribute($category, $category->getFooterText(), 'footer_text');?> 但请记住......如果你在foot ...
-
自定义类别页面模板(Custom Category Page Template)[2021-09-04]
如果要显示帖子内容,则需要在wordpress循环中使用the_content() 。 http://codex.wordpress.org/Function_Reference/the_content I thought i would contribute my answer to the above. I have coded this to display my categories with a date, the person who posted it and a time it was po ... -
从类别页面外的自定义类别属性获取值(Obtain the value from a custom category attribute outside category page)[2023-10-29]
尝试: $productsChildren = Mage::getModel('catalog/category')->getCategories(3,0,false,true,false); $productsChildren->addAttributeToSelect('category_subtitle') ->addAttributeToSelect('category_slidertext'); 如果$productsChildren是类别集合的实例,那将 ... -
您可能可以在注册表中检查密钥。 如果您在类别编辑页面上的后台,则注册了以下这些键: Mage::register('category', $category); Mage::register('current_category', $category); 干杯 You probably can check for keys in registry. If you're in the backoffice on a category edit page, you have these keys regist ...
-
我认为下面的代码可能无效,因为它使用了一个不推荐使用的参数(我认为 caller_get_posts在3.1中已弃用) 认为下面应该解决问题: $loop = new WP_Query( array( 'post_type' => 'portfolio', 'cat' => 5, // Whatever the category ID is for your aerial category 'posts_per_page' => 10, 'orderby' => 'dat ...
-
您不应该在独立脚本中更新数据库,但必须使用升级脚本... 如果你有,你不必手动实例化安装程序,也不会实例化坏的:你必须使用Mage_Catalog_Model_Resource_Setup (或Mage_Catalog_Model_Resource_Eav_Mysql4_Setup具体取决于您的magento版本),因为Mage_Catalog使用配置中配置的自定义安装程序类。 xml:
... -
首先,制作一个新的页面模板。 最简单的方法是复制当前的page.php文件并将其保存为:tutorials-page.php。 顶部包括: 然后使用以下自定义循环替换新tutorials-page.php文件中的循环: 'tutorials', //set the post_type to use. 'taxonomy' => 'tutorial ...
-
如何在magento的类别页面上检索所选的订单属性?(How to retrieve the chosen order attribute on category page in magento?)[2021-08-21]
getCurrentOrder(); ?> getCurrentOrder(); ?> -
您应该检查默认magento如何在URL中发送参数。 当URL将协议从http切换为https时,附加“?=”的参数将丢失。 请尝试使用以下格式:magento.com/fantasy/author/1/ 同时确保您的属性在分层导航中可过滤,并且您的类别被标记为锚。 希望这可以帮助!! You should check how default magento sends parameters in URL. When the URL switches the protocol that is from ht ...
-
类别或页面(Category or page)[2023-06-23]
我只看到两个选项: 改变你的网页永久链接 改变你的类别slu。 I see only two options : change your page permalink change your category slug