我正在创建一个按字母顺序排列的列表,其中还有一个字母显示在项目上方 - 参见图片:
这已经完成并且工作正常,但我需要让每个项目都可以点击,除了字母。
这是我的 MainActivity.java 代码的一部分(片段):
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_bohovia, container, false);
List<LetterSectionListItem> books = createBooks();
ListView bookListView = (ListView) rootView.findViewById(R.id.booklistview);
LetterSectionListAdapter bookListAdapter = new LetterSectionListAdapter(getContext(), R.layout.booklist_row, books) {
@NonNull
@Override
public View getView(int position, View v, ViewGroup parent) {
//Must call this before to wrap the header around the view
v = super.getView(position, v, parent);
TextView bookTitle = (TextView) v.findViewById(R.id.book_title);
TextView authorName = (TextView) v.findViewById(R.id.author_name);
Book book = (Book) this.getItem(position);
assert book != null;
bookTitle.setText(book.getBookName());
authorName.setText(book.getAuthorLastName() + ", " + book.getAuthorFirstName());
return v;
}
};
bookListView.setAdapter(bookListAdapter);
return rootView;
}
现在我尝试了什么:
我把这段代码放在那里,就在上面return rootView;
:
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(v.getContext(),SingleitemView.class);
intent.putExtra("place2", "test");
getContext().startActivity(intent);
}
});
但是,这工作正常,因此在单击该项目后打开另一个活动,而且当我单击独立字母时,我不希望有可单击的字母 A、B、C.. 等,只是下面的项目。
有人可以在这里提出建议,我做错了什么?