0
私のアプリケーションにCouchbaseを使用しています。私はrecyclerviewで検索データの問題に直面しています。リストがないのでフィルタロジックを使用できません。以下のコードをご覧ください。Couchbase lightフィルタデータ、Androidでの実装
private LiveQuery mQuery;
private QueryEnumerator enumerator;
public AllRecipeAdapter(Activity activity, ClickListner clickListner, LiveQuery query) {
this.mActivity = activity;
this.mClickListner = clickListner;
this.mQuery = query;
this.aListDocIds = new ArrayList<>();
refeshData();
}
private void refeshData() {
mQuery.addChangeListener(new LiveQuery.ChangeListener() {
@Override
public void changed(final LiveQuery.ChangeEvent event) {
((Activity) mActivity).runOnUiThread(new Runnable() {
@Override
public void run() {
enumerator = event.getRows();
notifyDataSetChanged();
}
});
}
});
mQuery.start();
notifyDataSetChanged();
Log.e("", "refeshData: ");
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_recipes, parent, false);
return new ViewHolder(mView);
}
@Override
public int getItemCount() {
return enumerator != null ? enumerator.getCount() : 0;
}
public Document getItem(int position) {
return enumerator != null ? enumerator.getRow(position).getDocument() : null;
}
public void invalidate() {
if (mQuery != null)
mQuery.stop();
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ViewHolder) {
Document document = (Document) getItem(position);
// Log.e(TAG, "onBindViewHolder: " + document.getId());
ImageView imgFeaturedRecipe = ((ViewHolder) holder).imgFeaturedRecipe;
String strDocId = (String) document.getProperty(_ID);
aListDocIds.add(strDocId);
String strRecipeName = (String) document.getProperty(RECIPENAME);
String strCookingTime = (String) document.getProperty(RECIPECOOKINGTIME);
String imgId = (String) document.getProperty(IMAGEID);
((ViewHolder) holder).txtRecipeName.setText(strRecipeName);
((ViewHolder) holder).txtRecipeTime.setText(strCookingTime);
ImageLoader.getInstance().setDisplayImage(mActivity, mActivity.getString(R.string.imageUrl) + imgId, imgFeaturedRecipe);
}
}
//アダプタコンストラクタでクエリパスを取得します。
private Query getQuery() {
return CBLSyncManager.getInstance(this).getListsView().createQuery();
}
/**
* Database View
*/
public View getListsView() {
View view = mDatabase.getView(VIEW_RECIPELIST);
if (view.getMap() == null) {
Mapper mapper = new Mapper() {
public void map(Map<String, Object> document, Emitter emitter) {
if (document.get(_ID).toString().contains(RCP)) {
String docID = (String) document.get(ID);
String strRecipeName = (String) document.get(RECIPENAME);
String strCookingTime = (String) document.get(RECIPECOOKINGTIME);
String[] temp = new String[]{docID, strRecipeName, strCookingTime};
emitter.emit(temp, null);
}
}
};
view.setMap(mapper, "1.0");
}
return view;
}
検索ボックスにユーザータイプとしてデータをフィルタリングしたいと考えています。