我正在尝试将var Months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var result = [];
result[0] = {January: 26.2, February: 25.9, March: 25.7, April: 23.4, May: 19.3, June: 15.9, July: 15.4, August: 16, September: 21.3, October: 24.8, November: 26.6, December: 26.6,Type: "Min"};
result[1] = {January: 36.3, February: 35.9, March: 36, April: 36.7, May: 34.2, June: 31.4, July: 32, August: 34, September: 37.8, October: 39.5, November: 39.8, December: 37.8,Type: "Max"};
var [min, max] = result.map(r => Months.map(m => {
return r[m]
}));
console.log(min);
console.log(max);
加载到map
中以使用值填充RecyclerAdapter
,但是在recyclerView
中,这些值已加载到地图中,但是{{1 }}不会收到有关这些更改的通知。我尝试检查valueEventlistener
的大小是否正确显示了值,但是当我检查adapter
内的map
时它为零。
getitemcount()
在adapter
方法中
private Map<String, OrderItem> convoModels = new HashMap<>();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_conversation);
inearLayoutManager mLayoutManager2
= new LinearLayoutManager(OrderConversation.this,
LinearLayoutManager.VERTICAL, false);
mCartList = (RecyclerView) findViewById(R.id.conversationlist);
mCartList.setLayoutManager(mLayoutManager2);
mAdapterConvo = new ConvoFirstAdapter(convoModels);
mCartList.setAdapter(mAdapterConvo);
loaddData();
}
loadData
类是
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds: dataSnapshot.getChildren()){
GenericTypeIndicator<Map<String, OrderItem>> to =
new GenericTypeIndicator<Map<String, OrderItem>>()
{};
Map<String, OrderItem> map = ds.getValue(to);
convoModels = ds.getValue(to);
mAdapterConvo.notifyDataSetChanged();
int i = mAdapterConvo.getItemCount();
Toast.makeText(OrderConversation.this, "size of map is "+
convoModels.size() + "size of adap "+ i,
Toast.LENGTH_SHORT).show();
for(OrderItem ml:convoModels.values()) {
String name = ml.getName();
Toast.makeText(OrderConversation.this, "name is "+
name, Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
答案 0 :(得分:0)
private Map<String, OrderItem> convoModels = new HashMap<>();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_conversation);
inearLayoutManager mLayoutManager2
= new LinearLayoutManager(OrderConversation.this,
LinearLayoutManager.VERTICAL, false);
mCartList = (RecyclerView) findViewById(R.id.conversationlist);
mCartList.setLayoutManager(mLayoutManager2);
Log.e(getClass().getSimpleName(),"Initi.... Adapter");
mAdapterConvo = new ConvoFirstAdapter(convoModels);
mCartList.setAdapter(mAdapterConvo);
loaddData();
}
LoaddData();
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds: dataSnapshot.getChildren()){
GenericTypeIndicator<Map<String, OrderItem>> to =
new GenericTypeIndicator<Map<String, OrderItem>>()
{};
Map<String, OrderItem> map = ds.getValue(to);
convoModels = ds.getValue(to);
mAdapterConvo.notifyDataSetChanged();
int i = mAdapterConvo.getItemCount();
/* Toast.makeText(OrderConversation.this, "size of map is "+
convoModels.size() + "size of adap "+ i,
Toast.LENGTH_SHORT).show(); */
Log.e("AddValueEent","size of map is: "+convoModels.size()+" size of Adap : "+i);
for(OrderItem ml:convoModels.values()) {
String name = ml.getName();
/*Toast.makeText(OrderConversation.this, "name is "+
name, Toast.LENGTH_SHORT).show();*/
Log.e("inLoop","Name is : "+name);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.e("inCancelled","Yes");
}
});