【发布时间】:2015-09-30 08:33:19
【问题描述】:
非常基本的问题:
我正在尝试动态启用/禁用ListView 的FooterView。
基本上,只要LocationListener 获得新位置,我想通过setEnable(true/false) 功能使其可点击。我正在考虑一个从LocationListener.onLocationChange() 方法中调用的公共方法,没有返回,但它必须更改FooterView 首选项,但我不知道如何对其进行编码,以及它是否可以工作。有什么建议吗?
在 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) {}
});
}
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);
}
因此,即使侦听器找到新位置,它也不会触发启用 footerView 的 if 条件(我在其中注释掉了代码)。 我试图从一个没有乐趣的方法访问 footerView.setEnable。任何帮助将不胜感激。
【问题讨论】:
标签: android android-listview textview