Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 自定义阵列适配器_Android_Arrays_Listview_Adapter_Custom Component - Fatal编程技术网

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

我正在编写一个新闻应用程序,在显示自定义列表时遇到了一些问题。我只希望列表项中有两个文本视图:

  • 新闻标题和
  • 新闻描述
它们包含在两个静态数组中:homeScreen.title[]和homeScreen.descriptionLong[]

下面是HashMap和适配器的代码:

最终静态ArrayList>data=new ArrayList>()

静态{
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
    }
});