The constructor SimpleAdapter(new View.OnClickListener(){},...)is undefined的问题及解决
来源:互联网 发布:淘宝运营常用软件 编辑:程序博客网 时间:2024/06/05 11:21
唉,效率好低的说,除了做日记本应用,同时也在做音乐播放器,虽然主要的代码完成了,但是出现了诸多问题。在日记本应用中,我想点击一个按钮显示保存的日志,然而在使用setOnClickListener的方法时,语法和填入的数据并没有问题,但仍然报错,我一直不知道原因,后来上网查了查,终于知道该怎么改了,在此和大家分享——
原来的代码:
//点击“获取日志列表”按钮,显示所有已保存日志的目录
searchBn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//如果SD卡存在
if(currentFile.exists()) {
//获取SD卡中的文件
currentFiles = currentFile.listFiles();
}
//创建一个List集合,其元素为Map
List<Map<String, Object>> diaryItems = new ArrayList<Map<String, Object>>();
for(int i = 0;i < currentFiles.length; i++) {
//判断是否为日志文件
if(currentFiles[i].getPath().endsWith(".txt")) {
Map<String, Object> diaryItem = new HashMap<String, Object>();
diaryFiles[j] = currentFiles[i];
diaryItem.put("diarytitle", diaryFiles[j]);
diaryItems.add(diaryItem);
j++;
}
}
//创建一个SimpleAdapter
adapter = new SimpleAdapter(this, diaryItems, R.layout.perform,
new String[]{"diarytitle"}, new int[]{R.id.diarytitle});
listView.setAdapter(adapter);
}
});
给出的解决方法是将adapter = new SimpleAdapter(this, diaryItems, R.layout.perform, new String[]{"diarytitle"}, new int[]{R.id.diarytitle});改成
adapter = new SimpleAdapter(MainActivity.this, diaryItems, R.layout.perform, new String[]{"diarytitle"}, new int[]{R.id.diarytitle});
但是我不知道为什么要这么改,希望有人看到劳烦解释一下,让更多不懂的人能够学习~谢谢啦~
- The constructor SimpleAdapter(new View.OnClickListener(){},...)is undefined的问题及解决
- The constructor Intent(new View.OnClickListener(){}, Class<ButtonStudyActivity>) is undefined
- 兔子--The constructor AlertDialog.Builder(new View.OnClickListener(){}) is undefined
- The constructor Intent(new View.OnClickListener(){}, Class<ButtonStudyActivity>) is undefined
- the constructor AlertDialog.Builder(new View.OnClickListener() ) is undefined
- The constructor Intent(new View.OnClickListener(){}, Class<ButtonStudyActivity>) is undefined
- 关于解决:the constructor AlertDialog.Builder(new View.OnClickListener() ) is undefined
- 关于“The constructor ArrayAdapter(new View.OnClickListener(){}, int, String[]) is undefined”错误提示的解决办法
- The constructor WeiboAuth(new View.OnClickListener(){}, String, String, String) is undefined
- The constructor SimpleAdapter(new View.OnClickListener(){}, List<Map<String,Object>>, ..的解决方法
- The constructor SimpleAdapter(new View.OnClickListener(){}, List<Map<String,Object>>,..)解决方法
- The constructor Date() is undefined问题的处理
- View OnclickListener与new DialogInterface.OnClickListener()冲突的问题
- The constructor Date() is undefined
- The constructor Date() is undefined
- 解决-The method setOnClickListener(View.OnClickListener) in the type View is not 错误
- 解决-The method setOnClickListener(View.OnClickListener) in the type View is not 错误
- 解决The method onClick(View) of type new View.OnClickListener(){} must override a superclass错误
- 病毒传播
- 解决ERROR 1201 (HY000): Could not initialize master info structure
- LocalBroadcastManager源码
- Linux - Bash shell的功能;内建命令type
- 读《数学之美》第三章 统计语言模型
- The constructor SimpleAdapter(new View.OnClickListener(){},...)is undefined的问题及解决
- HDOJ 1222 Wolf and Rabbit(数学解题技巧)
- hdu 1372 Knight Moves(经典BFS)
- 简易相册
- [HDU 2196] Computer 树形dp
- hdu 1558:Segment set
- makefile
- 三目运算符的简单介绍
- 最小生成树 prim算法和kruskal