0
我看到在github上有很多的例子,人們使用這樣的方法:的Android火力地堡無法解析方法getRef(位置)
String postKey = getRef(position).getKey();
但在我的Android工作室它不能解決getRef(int)
方法。這裏是代碼:
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
articleModel = new ArrayList<>();
for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
articleModel.add(postSnapshot.getValue(ArticleModel.class));
}
adapter = new ArticleAdapter(getActivity().getApplicationContext(), R.layout.fragment_article_list_items, articleModel);
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
Intent intent = new Intent(getActivity(), ArticleDetailsActivity.class);
String postKey = getRef(position).getKey();
intent.putExtra(ArticleDetailsActivity.EXTRA_POST_KEY, postKey);
getActivity().startActivity(intent);
}
});
}
有誰知道爲什麼發生這種情況,以及如何解決這個問題?
你可以給你看到'getRef(position)'工作的鏈接嗎? –
https://github.com/ikotrabakov/FireBlog/blob/017d8fe4df7b61ece00cad3e828e4a7cc8c5adcc/app/src/main/java/com/ivaylok/fireblog/MainActivity.java –
很可能您正在尋找adapter.getRef(position)。 –