- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
ListViews
一直是我的弱点,现在我正在练习将 Listview
放在 Listview
中。无论如何,我首先在我的程序开始时调用我的 ListView
,它用保存在我的 strings.xml
中的数组加载它:
String[] departments = getResources().getStringArray(
R.array.departments_array);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,
departments));
setContentView(R.layout.main);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
我想要做的是在每次单击列表项时使用新的值数组更新此 ListView
。我尝试这样做的原因是因为我计划有 27 个不同的数组,每个位置都有不同的值,而且我觉得如果不制作 ListView
的话,我的资源会更轻对于每个项目数组,我都会更新这个 ListView
。我知道我可能不是最有效的方法,但如果有另一种方法可以实现我的想法,请告诉我。
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
switch (position) {
case 0:
try {
//It is here that i dont know what to do, I was going to call
//the Listview the same way i did previously using my setlistadapter,
//but i kept getting errors about the code being undefined
String[] listitems1 = getResources().getStringArray(
R.array.items_array);
} catch (ClassCastException e) {
Toast.makeText(getApplicationContext(), "Error",
Toast.LENGTH_SHORT).show();
}
break;
case 1:
try {
//The listview will be changed again here
} catch (ClassCastException e) {
Toast.makeText(getApplicationContext(), "Error",
Toast.LENGTH_SHORT).show();
}
break;
}
};
});
最佳答案
您是否考虑过使用 BaseAdapter
并将其设置为列表适配器 http://developer.android.com/reference/android/widget/BaseAdapter.html
关于android - 复用同一个ListView展示不同的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9967245/
本文书接上回《反DDD模式之关系型数据库》,关注公众号(老肖想当外语大佬)获取信息: 最新文章更新; DDD框架源码(.NET、Java双平台); 加群畅聊,建模分析、技术实
我里面有 VC 和一个 collectionView。所有管理 Collection View 的代码我都放在那个 VC 的扩展中。但现在我需要在另一个不同的 VC 中使用这个 Collection
我很难重新使用子机图。 我需要重新使用我已链接到一个状态的状态机作为子机,在另一个状态中作为子机。但是当我给出对它的引用时,我得到一个空指针异常。 引用图片 我已经添加了对 GeneralTopup
我想尝试 lambda 的一些功能,并想编写一个 ArrayList 过滤器,并使用 IntStream 的方法来计算 ArrayList 中数字的平均值和最大值 我的第一个想法是过滤 ArrayLi
我正在开发一个 NodeJS 应用程序并使用 Mocha 进行单元测试。 假设我有两个非常相似的测试服。事实上,这些是针对两个类的测试实现相同的接口(interface)。 例如: suit_a.js
我正在使用 Glade 编写带有对话框的 python GUI。 如果我不使用 Glade,我会使用一个类来创建一个对话窗口 (dialag),运行它 (dialog.run),执行它所做的任何事情,
我在使用自定义单元格创建 UICollectionView 以显示项目时遇到问题。但是在 UICollectionView 刷新后,可重用的单元格填充了错误的索引 刷新前的 UICollectionV
我从 Sencha 学习 ExtJS 并有下一个简单的任务: 我的页面上有 2 个 div 在第一个 div 中我渲染 Ext.Button 在按钮上单击我想将其移动到另一个 div 仅此而已 我写了
我想在不同的 Node 模块中重用 RabbitMQ channel 。由于 channel 是异步创建的,我不确定将此 channel 对象“注入(inject)”到其他模块的最佳方法是什么。 如果
所以我的问题是我收到一个 SIGABRT 错误,其定义如下: *** Terminating app due to uncaught exception 'NSInvalidArgumentExcep
我正在编写一个 PHP 脚本来将主题从旧论坛站点迁移到新站点。 旧论坛站点使用数据库“old_forums” 新论坛站点使用数据库“new_forums” MySQL 用户“forums”拥有两个数据
我有一个使用 jcodec 生成的 MP4 文件。 然后我就有了一个使用 Android 的 MediaCodec 生成的 AAC 文件。 我想将它们混合到一个文件中,并且由于我不想将我的 Andro
我正在使用 ffmpeg 开发一个 c++ 项目。我必须生成一个带有 h264 编码的 mp4 文件。 我的问题是文件生成但是当用 VLC 读取文件时我没有图像,并用 ffprobe 分析它给我(下面
我将尝试重新提出这个问题。 我想要做的是创建一个新的 mp4 文件,其中将包括一个视频文件、两个音频文件和一个字幕文件。我想创建一个可以在我的 iOS 设备和计算机上播放的 mp4 文件。 文件如下:
虽然我的问题可能看起来很抽象,但我希望不是。假设我开发了一个应用程序,一个 ASP.NET MVC 站点,然后我的任务是为这个应用程序构建一个 Winforms 客户端,我可以从现有应用程序中重用多少
我是一名优秀的程序员,十分优秀!