java微调器_使用微调器填充RecyclerView

我正在从Firebase的Firestore DB加载一个列表来填充一个微调器 . 这样可行 . 我想在微调器中的ItemSelected上填充RecyclerView .

我有这个代码来填充RecyclerView:

private void populateRecycler(final String RootCollection, final String UserID) {

final String UserID = getIntent().getExtras().getString(UserIDKey);

mQuery = mFirestore

.collection(RootCollection)

.whereEqualTo("UID", UserID)

.orderBy("DateAdded", Query.Direction.DESCENDING);

mAdapter = new OrdersAdapter(mQuery, HomeActivity.this);

mOrdersRecycler.setLayoutManager(new LinearLayoutManager(getApplicationContext()));

mOrdersRecycler.setAdapter(mAdapter);

}

如果从onCreate放置或调用此代码,则此代码可以正常工作 . 但是我想稍后修改代码,以便稍后在spinner中填充String . (可能只是为了添加另一个.whereEqualto)

当我从这里打电话给 populateRecycler() 时,它不会使用ButterKnife,fyi):'t work (I'

@OnItemSelected(R.id.storespinner)

public void spinnerItemSelected(Spinner spinner, int position) {

String spinnerValue = mStoreSpinner.getItemAtPosition(position).toString();

Toast.makeText(getBaseContext(), "Selected item " + spinnerValue, Toast.LENGTH_SHORT).show();

populateRecycler("test", UserID);

}

或者,如果我从另一个onSuccess侦听器(Firebase Firestore数据库调用)调用populateRecycler,它也不起作用:

public void onSuccess(DocumentSnapshot documentSnapshot) {

UIDOrg uidOrg = documentSnapshot.toObject(UIDOrg.class);

mOrgTextView.setText(uidOrg.getOrg());

RootCollection = uidOrg.getRootCollection();

populateRecycler("test", UserID);

有人可以指点我正确的方向吗?

为什么 populateRecycler 仅在从onCreate调用时才起作用?

编辑:这是我填充微调器数组的方式 .

public void onSuccess(DocumentSnapshot documentSnapshot) {

UIDOrg uidOrg = documentSnapshot.toObject(UIDOrg.class);

mOrgTextView.setText(uidOrg.getOrg());

RootCollection = uidOrg.getRootCollection();

//Populate Spinner here

readData(new FirestoreCallBack() {

@Override

public void onCallback(List list) {

ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, list);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

mStoreSpinner.setAdapter(adapter);

}

});

//End of Spinner

}

在readData()中它是:

public void onComplete(@NonNull Task task) {

if (task.isSuccessful()) {

for (DocumentSnapshot document : task.getResult()) {

spinnerArray.add(String.valueOf(document.getId()));

}

firestoreCallBack.onCallback(spinnerArray);

} else {

Log.d(TAG, "Error getting documents: ", task.getException());

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值