Android 如何打开特定项目上的编辑文本是从微调器中选择的

Android 如何打开特定项目上的编辑文本是从微调器中选择的,android,Android,我构建了一个微调器,在其中我将元素放入数组列表,并将“从微调器中获取选定项”的值存储在一个变量中,在我的微调器中它有15个元素,现在我想尝试从微调器中选择特定项时,打开一个带有“编辑文本”和“编辑”按钮的对话框,然后用户可以在微调器中编辑和保存它。我如何做到这一点 我的微调器代码是 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

我构建了一个微调器,在其中我将元素放入数组列表,并将“从微调器中获取选定项”的值存储在一个变量中,在我的微调器中它有15个元素,现在我想尝试从微调器中选择特定项时,打开一个带有“编辑文本”和“编辑”按钮的对话框,然后用户可以在微调器中编辑和保存它。我如何做到这一点

我的微调器代码是

            public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.faultid);

              addItemsOnSpinner2();
       addListenerOnSpinnerItemSelection();

                     }


      public void addListenerOnSpinnerItemSelection()
        {

            Spinner faultSpinner = (Spinner) findViewById(R.id.spinner1);
            mspinner.setOnItemSelectedListener(new 
                     CustomOnItemSelectedListener());

        }

                  public void addItemsOnSpinner2() {

             ArrayList<String> faulttypespinner = new ArrayList<String>();
             faulttypespinner.add("XL-Cross Level");
             faulttypespinner.add("AL-Alignment");
             faulttypespinner.add("UN-Unevenness");
             faulttypespinner.add("XL-Cross Level");
             faulttypespinner.add("AL-Alignment");
             faulttypespinner.add("UN-Unevenness");
             faulttypespinner.add("BD-Ballast Deficiency");
             faulttypespinner.add("SE-Super elevation on curve");
             faulttypespinner.add("LP-Loose Packing");
             faulttypespinner.add("LJ-Low Joint");
             faulttypespinner.add("BA-Bridge");
             faulttypespinner.add("LC-Level Crossing");
             faulttypespinner.add("LJ-Low Joint");
             faulttypespinner.add("P and C-Point n Xing");
             faulttypespinner.add("OTH-Other Defect");
             faulttypespinner.add("SEJ-SEJ");
             faulttypespinner.add("WEED-Weed on Cess");

           ArrayAdapter<String> faultadapter = new ArrayAdapter<String>
          (mConetxt,android.R.layout.simple_spinner_item, faulttypespinner);

    faultadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
             mspinner.setAdapter(faultadapter);


 }

      public class CustomOnItemSelectedListener implements OnItemSelectedListener {

     public void onItemSelected(AdapterView<?> parent, View view, int pos,
        long id) {

    Toast.makeText(parent.getContext(), 
            "OnItemSelectedListener : " + 
             parent.getItemAtPosition(pos).toString(),
            Toast.LENGTH_SHORT).show();
}
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.faultid);
addItemsOnSpinner2();
addListenerOnSpinnerItemSelection();
}
public void addListenerOnSpinnerItemSelection()
{
微调器faultSpinner=(微调器)findViewById(R.id.spinner1);
mspinner.setOnItemSelectedListener(新建)
CustomOnItemSelectedListener());
}
公共无效附加项Spinner2(){
ArrayList faulttypespinner=新的ArrayList();
faulttypespinner.add(“XL交叉级别”);
faulttypespinner.add(“AL对齐”);
faulttypespinner.添加(“不均匀”);
faulttypespinner.add(“XL交叉级别”);
faulttypespinner.add(“AL对齐”);
faulttypespinner.添加(“不均匀”);
faulttypespinner.add(“BD镇流器不足”);
faulttypespinner.add(“曲线上的SE超高”);
faulttypespinner.添加(“LP散装”);
faulttypespinner.add(“LJ低接头”);
faulttypespinner.add(“BA桥”);
faulttypespinner.add(“LC平交道口”);
faulttypespinner.add(“LJ低接头”);
faulttypespinner.add(“P点和C点n行”);
faulttypespinner.添加(“其他缺陷”);
faulttypespinner.add(“SEJ-SEJ”);
faulttypespinner.add(“在Cess上除草”);
ArrayAdapter faultadapter=新的ArrayAdapter
(mconext,android.R.layout.simple\u微调器\u项,faulttypespinner);
faultadapter.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
mspinner.setAdapter(faultadapter);
}
公共类CustomOnItemSelectedListener实现OnItemSelectedListener{
已选择公共视图(AdapterView父视图、视图、int pos、,
长id){
Toast.makeText(parent.getContext(),
“OnItemSelectedListener:”+
parent.getItemAtPosition(pos.toString(),
吐司。长度(短)。show();
}

您需要
实现自定义适配器
,其中您将有一个类似以下内容的方法:

public void changeItemValue(int position, String newValue){
    Item itm = getItem(position);
    itm.setValue(newValue);
    notifyDataSetChanged();
}

当您打开SelectEdItem上的
对话框时,您必须将
微调器适配器的
实例
传递给
对话框
,然后传递给
对话框按钮
侦听器
,您将
调用
按钮上的
changeItemValue方法

为什么要使用自定义适配器,当单击微调器时,获取单击项的位置并显示弹出窗口,然后单击按钮,使用以前存储的索引将值设置为faulttypespinner arraylist。然后添加notifydatasetchanged for adapter以更新微调器,仅此而已。

您的问题不完整,您想将数据存储在什么位置当用户选择“其他缺陷”时,我的微调器中的编辑文本框SIR然后用“编辑文本”按钮打开一个对话框,然后它存储在微调器上以及微调器中的当前元素。您是对的,先生,但我不明白如何打开从微调器中选择的特定项目的弹出窗口。先生,请在我的代码中编辑或提供一些参考。先生,我不明白我该怎么做