防止在列表视图中单击标题视图?

时间:2014-01-16 20:13:20

标签: java android listview android-listview

我最初在列表视图中添加了一个标题视图,并设置了一个onItemClick监听器:

SimpleAdapter mAdapter = new SimpleAdapter(_context, bookList, R.layout.list_view, 
                             new String[]{ "name","summary", "published" },
                             new int[] { R.id.bookTitle,R.id.bookSummary,R.id.bookPublished });
mBookList.setAdapter(mAdapter);
mBookList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view,int position, long id) {                   
        @SuppressWarnings("unchecked")
        HashMap<String, String> bookMap = (HashMap<String,String>)parent.getItemAtPosition(position);

        String url = bookMap.get("site_url").toString();
        String bookName = bookMap.get("name").toString();

        Intent intent = new Intent(_context, BookViewClass.class);
        intent.setData(Uri.parse(url));
        intent.putExtra("name", bookName);

        _context.startActivity(intent);
    }
});

问题是,当单击标题视图时,我遇到崩溃,所有其他单元格都正常工作。我该如何防止这种情况发生?

1 个答案:

答案 0 :(得分:1)

在你的ONItemClickListener中你可以检查位置是否为0并忽略它。