嗨,我正在制作一个创建图形以添加边的应用程序,我选择通过对话框获取它,其中显示了所有已完成的节点,如何将List的数据发送给Dialog的微调器? / p>
这是我创建节点和边的菜单:
private BottomNavigationView.OnNavigationItemSelectedListener selectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add_node:
if (pos < criaNos.length) {
graph.addNode(criaNos[pos]);
graph.getNode(criaNos[pos]).setAttribute("ui.label", criaNos[pos]);
graph.getNode(criaNos[pos]).setAttribute("xy", x, y);
nos.add(criaNos[pos]);
pos++;
x += 2.0f;
y += 1.5f;
}else {
Toast.makeText(getActivity(), "Não pode adcionr mais nós", Toast.LENGTH_SHORT).show();
}
return true;
case R.id.action_add_aresta:
openDialogAddAresta();
return true;
case R.id.action_remover:
Toast.makeText(getActivity(), "Ultimo no"+nos.get(0), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
};
调用我的对话框的
public void openDialogAddAresta() {
adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item);
DialogAddAresta dialogAddAresta = new DialogAddAresta();
dialogAddAresta.show(getActivity().getSupportFragmentManager(), "Add Aresta");
}
我在其他班级的对话
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(Objects.requireNonNull(getActivity()));
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.layout_dialog_add_aresta, null);
spTo = view.findViewById(R.id.sp_to);
spFrom = view.findViewById(R.id.sp_from);
ArrayAdapter<String> nodeTo = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_spinner_dropdown_item
);
nodeTo.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spTo.setAdapter(nodeTo);
builder.setView(view)
.setTitle("Add Aresta")
.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setPositiveButton("Add", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
return builder.create();
}
出现对话框,但我无法在微调器上得到数据。