我正在尝试应用我在Github中找到的Indexable ListView:https://github.com/woozzu/IndexableListView。但我的问题是如何在Custom ArrayAdapter中实现它?我正在使用firebase,我想在listview中显示我的数据,但我的问题是我也想用Indexable ListView实现它,但我不能,因为我实现它时出现了一些错误,因为它说不兼容。有没有任何方法可以在我的程序中实现Indexable ListView?
以下是我的代码部分:
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
bookList.clear();
for (DataSnapshot bookSnapshot : dataSnapshot.getChildren()) {
Book books = bookSnapshot.getValue(Book.class);
bookList.add(books);
}
BookList adapter = new BookList(getActivity(),bookList);
ViewBook.setAdapter(adapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
BookList.java - Custom ArrayAdapter
public class BookList extends ArrayAdapter<Book> {
private Activity context;
private List<Book> bookList;
private List<Image> imageList;
private ImageView image;
public BookList(Activity context, List<Book> bookList){
super(context, R.layout.list_layout,bookList);
this.context=context;
this.bookList=bookList;
this.imageList=imageList;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listViewItem= inflater.inflate(R.layout.list_layout,null,true);
TextView textViewTitle = (TextView) listViewItem.findViewById(R.id.textViewTitle);
TextView textViewAuthor = (TextView) listViewItem.findViewById(R.id.textViewAuthor);
image = (ImageView) listViewItem.findViewById((R.id.ivUploadImage));
Book books = bookList.get(position);
textViewTitle.setText(books.getBookTitle());
textViewAuthor.setText(books.getAuthorName());
Picasso.with(context).load(books.getBookImageUrl()).into(image);
return listViewItem;
}
}
Book.java
public class Book {
String bookId;
String bookTitle;
String authorName;
String bookDescription;
String bookPublisher;
String bookPages;
String bookISBN;
String bookEdition;
String bookImageUrl;
public Book() {
}
public Book(String bookId, String bookTitle, String authorName, String
bookDescription,String bookPublisher, String bookPages, String bookISBN,
String bookEdition, String bookImageUrl) {
this.bookId = bookId;
this.bookTitle = bookTitle;
this.authorName = authorName;
this.bookDescription = bookDescription;
this.bookPublisher = bookPublisher;
this.bookPages = bookPages;
this.bookISBN = bookISBN;
this.bookEdition = bookEdition;
this.bookImageUrl = bookImageUrl;
}
public String getBookId() {
return bookId;
}
public String getBookTitle() {
return bookTitle;
}
public String getAuthorName() {
return authorName;
}
public String getBookDescription() {
return bookDescription;
}
public String getBookPublisher() {
return bookPublisher;
}
public String getBookPages() {
return bookPages;
}
public String getBookISBN() {
return bookISBN;
}
public String getBookEdition() {
return bookEdition;
}
public String getBookImageUrl() {
return bookImageUrl;
}
}