热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何动态修改FooterView的首选项?-HowtomodifypreferenceofaFooterViewdynamically?

Verybasicquestion:ImtryingtoenabledisabletheFooterViewofaListViewdynamically.Basicall

Very basic question: I'm trying to enable/disable the FooterView of a ListView dynamically. Basically I would like to make it clickable through the setEnable(true/false) function as soon as the LocationListener acquires a new location. I was thinking about a public method that get called from within the LocationListener.onLocationChange() method, with no return but it has to change the FooterView preference, but I can't figure out how to code it, and if it could work. Any suggestions?

非常基本的问题:我正在尝试动态启用/禁用ListView的FooterView。基本上我想在LocationListener获取新位置后通过setEnable(true / false)函数使其可单击。我正在考虑从LocationListener.onLocationChange()方法中调用的公共方法,没有返回,但它必须更改FooterView首选项,但我无法弄清楚如何编写它,以及它是否可以工作。有什么建议?

In onCreate:

@Override
protected void onCreate(Bundle bundle) {
    LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    TextView footerView = (TextView)inflater.inflate(R.layout.footer_view, null);
    myListView.addFooterView(footerView);
    //if (!enabler) footerView.setEnabled(false);
    //else footerView.setEnabled(true);
    footerView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {}
    });
}

The LocationListener methods

LocationListener方法

@Override
public void onLocationChanged(Location currentLocation) {
    if (null == mLastLocationReading || mLastLocationReading.getTime() > currentLocation.getTime()){
        mLastLocatiOnReading= currentLocation;
        enabler=true;
    }
    if (currentLocation.getTime() > mLastLocationReading.getTime())
        mLocationManager.removeUpdates(this);
}

So even if the Listener find a new location it doesn't trigger the if condition enabling the footerView (where I commented out the code). I tried to access footerView.setEnable from a method with no joy. Any help would be very much appreciated.

因此,即使监听器找到一个新位置,它也不会触发启用footerView的if条件(我在其中注释掉了代码)。我试图从没有快乐的方法访问footerView.setEnable。任何帮助将非常感谢。

1 个解决方案

#1


0  

Why your solution is not working is because onCreate() is called only once, when the Activity is being created.

为什么你的解决方案不起作用是因为在创建Activity时只调用onCreate()一次。

Try the following:

请尝试以下方法:

class YourActivity extends Activity implements LocationListener {

    private TextView footerView;

    @Override
    protected void onCreate(Bundle bundle) {
        LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        footerView = (TextView)inflater.inflate(R.layout.footer_view, null);
        myListView.addFooterView(footerView);
        footerView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {}
        });
    }

    @Override
    public void onLocationChanged(Location currentLocation) {
        if (null == mLastLocationReading || mLastLocationReading.getTime() > currentLocation.getTime()){
            mLastLocatiOnReading= currentLocation;
            enableFooterView(true);
        }
        if (currentLocation.getTime() > mLastLocationReading.getTime())
            mLocationManager.removeUpdates(this);
    }

    private void enableFooterView(boolean enable) {
        footerView.setEnabled(enable);
    }
}

推荐阅读
  • 概述Android开发过程中,经常遇到Textview展示不完全的情况。遇到此情况,通常的处理是:方案一Textview添加android:ellipsize属性,让展示不 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • TextView属性详解:autoLink设置  是否当文本为URL链接email电话号码map时,文本显示为可点击的链接。可选值(nonewebemailphonema ... [详细]
  • 本文介绍了闭包的定义和运转机制,重点解释了闭包如何能够接触外部函数的作用域中的变量。通过词法作用域的查找规则,闭包可以访问外部函数的作用域。同时还提到了闭包的作用和影响。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • 展开全部下面的代码是创建一个立方体Thisexamplescreatesanddisplaysasimplebox.#Thefirstlineloadstheinit_disp ... [详细]
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
  • 如何查询zone下的表的信息
    本文介绍了如何通过TcaplusDB知识库查询zone下的表的信息。包括请求地址、GET请求参数说明、返回参数说明等内容。通过curl方法发起请求,并提供了请求示例。 ... [详细]
  • scroll-在Android上使TextView可滚动我在textview中显示文本似乎太长而不适合进入一个屏幕。我需要让我的TextView可滚动。我能怎么做那? ... [详细]
  • 1.范例说明EditTextWidget设计的初衷是为了等待User输入而准备的,那么在User输入的同时,又该如何拦截所输入的文字呢?Android的多数Widget都有 ... [详细]
  • 首选我们找到源码中的TextView找到textsize属性一个int类型默认值为15初使化自定义属性:我们看一个getDeimensionPixelSiz ... [详细]
  • Android TextView利用measureText自适应文本字体大小宽度
    AndroidTextView利用measureText自适应文本字体大小宽度常常有这种情况,UI设计师限定一个文本TextView的宽度值比如80dip,但是该文本长度 ... [详细]
author-avatar
小丽丽很可爱
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有