package com.example.nemophila;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import com.example.nemophila.entities.Shop;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class MapsDialogFragment extends DialogFragment {
private Collection<Shop> shops;
public MapsDialogFragment(Collection<Shop> shops) {
this.shops = shops;
}
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
String[] choices = new String[shops.size()];
//ArrayList<String> choices = new ArrayList<>();
int j = 0;
for (Iterator i = shops.iterator(); i.hasNext(); j++) {
Shop tmp = (Shop)i.next();
choices[j] = tmp.getName();
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("投稿したいお店はこの中にありますか?")
.setPositiveButton("該当する店がありません(新規作成)", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//このボタンを押した時の処理を書きます。
//新規投稿画面へ遷移
}
})
.setNeutralButton("キャンセル", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// このボタンを押した時の処理を書きます。
}
})
.setItems(choices, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getActivity(),
String.format("「%s」を選択しました。", choices[which]),
Toast.LENGTH_SHORT)
.show();
}
});
return builder.create();
}
}