我有一个简单的ParseQuery,它可以检索一个类' PrivateData'的单个对象。
ParseQuery<PrivateData> query = ParseQuery.getQuery(PrivateData.class);
query.whereEqualTo("user", ParseUser.getCurrentUser());
然后可以使用此代码使用PrivateData类中的数据填充listView。
但我的要求是拥有一个CardListView并填充标题。
如何使用我从parse.com获得的数据设置卡片标题?
public class HistoryActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.history_fragment);
// get action bar
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
// Enabling Up / Back navigation
actionBar.setDisplayHomeAsUpEnabled(true);
/*
1. Issue the parse query
2. Set the result from the query to each card title of CardListView
3. Repeat step 1 and step 2 until we get all the results and they are populated dynamically in CardsListView
*/
}
答案 0 :(得分:0)
问题出在哪里?
ArrayList<Card> cards = new ArrayList<Card>();
for (int i = 0; i < query.count; i++) {
Card card = new Card(getActivity());
card.setTitle(xxx);
cards.add(card);
}
mCardArrayAdapter.addAll(cards);
mCardArrayAdapter.notifyDataSetChanged();
当然,您可以使用带有自定义布局的自定义卡片作为标题。
答案 1 :(得分:0)
谢谢Gabriele Mariotti!所以我想我明白了。这是代码。 欢迎提出建议和/或改进。
ParseQuery<PrivateData> query = new ParseQuery<>("PrivateData");
query.whereEqualTo("user", ParseUser.getCurrentUser());
query.orderByDescending("createdAt");
query.setCachePolicy(ParseQuery.CachePolicy.CACHE_THEN_NETWORK);
query.findInBackground(new FindCallback<PrivateData>() {
@Override
public void done(List<PrivateData> data, ParseException error) {
if (data != null) {
CardArrayAdapter mCardArrayAdapter;
CardListView cardListView;
Card card;
ArrayList<Card> cardArrayList = new ArrayList<>();
for (int i = 0; i < data.size(); i++) {
card = new Card(getApplicationContext());
card.setTitle("Created At : " + data.get(i).getCreatedAt().toString());
cardArrayList.add(card);
}
mCardArrayAdapter = new CardArrayAdapter(getApplicationContext(), cardArrayList);
cardListView = (CardListView) findViewById(R.id.history_card_view);
cardListView.setAdapter(mCardArrayAdapter);
}
}
});