Android 自定义阵列适配器
我正在编写一个新闻应用程序,在显示自定义列表时遇到了一些问题。我只希望列表项中有两个文本视图:Android 自定义阵列适配器,android,arrays,listview,adapter,custom-component,Android,Arrays,Listview,Adapter,Custom Component,我正在编写一个新闻应用程序,在显示自定义列表时遇到了一些问题。我只希望列表项中有两个文本视图: 新闻标题和 新闻描述 它们包含在两个静态数组中:homeScreen.title[]和homeScreen.descriptionLong[] 下面是HashMap和适配器的代码: 最终静态ArrayList>data=new ArrayList>() 静态{ HashMap行=新建HashMap(); 对于(int i=0;i您应该将行实例化放在for循环中: for (int i = 0; i
- 新闻标题和
- 新闻描述
静态{
HashMap行=新建HashMap();
对于(int i=0;i您应该将行
实例化放在for
循环中:
for (int i = 0; i<HomeScreen.arrayLength; i++){
HashMap<String, String> row = new HashMap<String, String>();
row.put("Title", HomeScreen.title[i]);
row.put("Description", HomeScreen.descriptionLong[i]);
data.add(row);
}
非常感谢。这是一个很大的帮助。我仍然有一个问题。默认的OnItemClick不起作用。我将编辑并添加上面的代码。非常感谢你花时间帮助像我这样的noobs!
for (int i = 0; i<HomeScreen.arrayLength; i++){
HashMap<String, String> row = new HashMap<String, String>();
row.put("Title", HomeScreen.title[i]);
row.put("Description", HomeScreen.descriptionLong[i]);
data.add(row);
}
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// your code here
}
});