小编use*_*346的帖子

Android:如何从Spinner获取所选项目的ID

在我的情况下,我想从Spinner获取所选项目的Id.我的模态类中有两个字段,分别是id和name.我列出了所有数据,并将此列表设置为适配器.我试图通过使用getSelectedItem()方法获取selectedItem Id.但我只能获得项目列表的第一个id.

这是我的代码.

public class ModifyEventFragment extends DialogFragment{
Context context;
CalEvent eve;
Project proj;
Spinner eventType,stage;
public static String eid,pid,type;
public static List<EventType> event_type;
public static List<ProjectStatus> cust_stage;
EditText where,when,who,notes;
String eve_type,stage_val,when_val,who_val,notes_val;
String modified_where,modified_who,modified_when,modified_notes;
public ModifyEventFragment(Project proj)
{
    this.proj=proj;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.modify_project_event, container,
            false);
    context = rootView.getContext();
    eventType = (Spinner) rootView.findViewById(R.id.modifyEventType);
    stage =(Spinner) rootView.findViewById(R.id.modifyStage);
    where = (EditText)rootView.findViewById(R.id.modifyWhere);
    who = (EditText)rootView.findViewById(R.id.modifyWho);
    when = (EditText)rootView.findViewById(R.id.modifyWhen);
    notes =(EditText) rootView.findViewById(R.id.modifyNotes);
    eve = …
Run Code Online (Sandbox Code Playgroud)

android spinner android-spinner

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

android-spinner ×1

spinner ×1