Ich konnte AWS DynamoDb abfragen und Ergebnisse abrufen. Die Ergebnisse stammen aus einer Song-Datenbank und geben Informationen wie Son Name, Musiker, URL usw. zurück. Die Anzahl der Ergebnisse kommt wie erwartet zurück, daher denke ich, dass die Abfrage korrekt funktioniert. Dies ist wahrscheinlich sehr einfach, aber ich bin mir nicht sicher, wie ich die einzelnen Artikel aus der Liste abrufen soll, sobald ich sie habe.Android einzelne Elemente aus einer paginierten Abfrageliste abrufen
Das ist mein Modell:
@DynamoDBTable(tableName = "Music")
public class SongDatabaseMappingAdapter {
private String artist;
private String songtitle;
private String albumtitle;
private String category;
private int musicianrating;
private int userrating;
private String pictureurl;
private String songurl;
@DynamoDBHashKey(attributeName = "Artist")
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
@DynamoDBRangeKey(attributeName = "SongTitle")
public String getSongTitle() {
return songtitle;
}
public void setSongTitle(String songtitle) {
this.songtitle = songtitle;
}
@DynamoDBAttribute(attributeName = "AlbumTitle")
public String getAlbumTitle() {
return albumtitle;
}
public void setAlbumTitle(String albumtitle) {
this.albumtitle = albumtitle;
}
@DynamoDBIndexHashKey(attributeName = "Category", globalSecondaryIndexName = "Category-UserRating-index")
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
@DynamoDBAttribute(attributeName = "MusicianRating")
public int getMusicianRating() {
return musicianrating;
}
public void setMusicianRating(int musicianrating) {
this.musicianrating = musicianrating;
}
@DynamoDBIndexRangeKey(attributeName = "UserRating", globalSecondaryIndexName = "Category-UserRating-index")
public int getUserRating() {
return userrating;
}
public void setUserRating(int userrating) {
this.userrating = userrating;
}
@DynamoDBAttribute(attributeName = "PictureURL")
public String getPictureURL() {
return pictureurl;
}
public void setPictureURL(String pictureurl) {
this.pictureurl = pictureurl;
}
@DynamoDBAttribute(attributeName = "SongURL")
public String getSongURL() {
return songurl;
}
public void setSongURL(String songurl) {
this.songurl = songurl;
}
}
Und das ist meine Frage:
public class getSongsInCategory extends AsyncTask {
@Override
protected Object doInBackground(Object[] params) {
SongDatabaseMappingAdapter songs = new SongDatabaseMappingAdapter();
songs.setCategory("Rap");
String userRatingQueryString = "5";
Condition rangeKeyCondition = new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue().withN(userRatingQueryString));
DynamoDBQueryExpression queryExpression = new DynamoDBQueryExpression()
.withHashKeyValues(songs)
.withIndexName("Category-UserRating-index")
.withRangeKeyCondition("UserRating", rangeKeyCondition)
.withConsistentRead(false);
PaginatedQueryList<SongDatabaseMappingAdapter> result = mapper.query(SongDatabaseMappingAdapter.class, queryExpression);
Dies ist, wie ich die Ergebnisse überprüft wurden:
for (int i = 0; i < result.size(); ++i) {
SongDatabaseMappingAdapter obj = result.get(i);
Log.i("Query Result", "Number"+i+obj.toString());
}
Und das sind die Ergebnisse, die ich bekommen habe:
05-22 03:42:12.313 27594-27628/com.amazon.mysampleapp I/Query Result: [email protected]
05-22 03:42:12.313 27594-27628/com.amazon.mysampleapp I/Query Result: [email protected]
05-22 03:42:12.317 27594-27628/com.amazon.mysampleapp I/Query Result: [email protected]
05-22 03:42:12.317 27594-27628/com.amazon.mysampleapp I/Query Result: [email protected]
Also ich weiß, dass es zumindest teilweise funktioniert, aber jetzt möchte ich die einzelnen Teile aus der Songabfrage holen und sie in einen Textviews, Imageviews Media Player ect.
Ich mag mich irren, aber ich denke, ich muss das Modell verwenden, das ich erstellt habe, aber ich bin mir nicht sicher, wie.
Danke für Ihre Hilfe.
genial, dass es getan hat. Danke für die Hilfe. –