このメソッドには、ArrayLists に解析され、配列に設定され、アラート ダイアログで使用さonCreate
れる JSON を返すネットワーク操作があります。CharSequence[]
ただし、選択すると、結果の JSON データがアラートに取り込まれません。ここまでで、Volley の実装が機能し、データが ArrayLists に渡されることがわかりました。失敗の領域は、ArrayList データをCharSequence[]
配列に渡し、それが AlertDialog に渡されることです。
// Initialize Volley:
final RequestQueue requestQueue = VolleySingleton.getsInstance().getRequestQueue();
getUsersGroupsURL = usersGroupsActionURL + hardUserName + JSON;
JsonObjectRequest getGroupData = new JsonObjectRequest(Request.Method.GET, getUsersGroupsURL, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// Parse the JSON:
try {
groupResults = response.getJSONArray("users_groups");
for (int i = 0; i <= groupResults.length() - 1; i++) {
JSONObject oneGroup = groupResults.getJSONObject(i);
groupNameList.add(oneGroup.getString("groupName"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Error.Response", error.toString());
}
}
);
requestQueue.add(getGroupData);
groupNames = groupNameList.toArray(new CharSequence[groupNameList.size()]);
inviteFriend.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
final CharSequence[] items = {
"Share an Idea", "Share a story"
};
AlertDialog.Builder builder = new AlertDialog.Builder(SingleSpecial.this);
builder.setTitle(R.string.sharing_type);
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int selection) {
if (selection == 0) {
// Create the lists of groups and friends
// If the first, go to the selection of friend/group
AlertDialog.Builder openFriends = new AlertDialog.Builder(SingleSpecial.this);
openFriends.setTitle(R.string.sharing_type);
openFriends.setItems(groupNames, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int selection) {
}
});
AlertDialog openFriendsAlert = openFriends.create();
openFriendsAlert.show();
} else if (selection == 1) {
// If the second, select location, then the friend/group
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
失敗は、ネットワーク操作が完了するまでの時間と AlertDialog の入力に関係していると思います。
ネストされたデータを取り込むにはどうすればよいAlertDialog
ですか?