久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='Lz899'></tfoot>

  • <i id='Lz899'><tr id='Lz899'><dt id='Lz899'><q id='Lz899'><span id='Lz899'><b id='Lz899'><form id='Lz899'><ins id='Lz899'></ins><ul id='Lz899'></ul><sub id='Lz899'></sub></form><legend id='Lz899'></legend><bdo id='Lz899'><pre id='Lz899'><center id='Lz899'></center></pre></bdo></b><th id='Lz899'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Lz899'><tfoot id='Lz899'></tfoot><dl id='Lz899'><fieldset id='Lz899'></fieldset></dl></div>
        <legend id='Lz899'><style id='Lz899'><dir id='Lz899'><q id='Lz899'></q></dir></style></legend>

          <bdo id='Lz899'></bdo><ul id='Lz899'></ul>
      1. <small id='Lz899'></small><noframes id='Lz899'>

        如何從 Android 中每個動態(tài)創(chuàng)建的 EditText 獲取數(shù)據(jù)

        How to get data from each dynamically created EditText in Android?(如何從 Android 中每個動態(tài)創(chuàng)建的 EditText 獲取數(shù)據(jù)?)
        <tfoot id='3jBZH'></tfoot>
          <tbody id='3jBZH'></tbody>

        • <legend id='3jBZH'><style id='3jBZH'><dir id='3jBZH'><q id='3jBZH'></q></dir></style></legend>
            1. <small id='3jBZH'></small><noframes id='3jBZH'>

              • <bdo id='3jBZH'></bdo><ul id='3jBZH'></ul>

                1. <i id='3jBZH'><tr id='3jBZH'><dt id='3jBZH'><q id='3jBZH'><span id='3jBZH'><b id='3jBZH'><form id='3jBZH'><ins id='3jBZH'></ins><ul id='3jBZH'></ul><sub id='3jBZH'></sub></form><legend id='3jBZH'></legend><bdo id='3jBZH'><pre id='3jBZH'><center id='3jBZH'></center></pre></bdo></b><th id='3jBZH'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3jBZH'><tfoot id='3jBZH'></tfoot><dl id='3jBZH'><fieldset id='3jBZH'></fieldset></dl></div>

                  本文介紹了如何從 Android 中每個動態(tài)創(chuàng)建的 EditText 獲取數(shù)據(jù)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我已經(jīng)根據(jù) Android 中的用戶輸入成功創(chuàng)建了 EditText,并且我還使用 setId() 方法為它們分配了唯一 ID.

                  I have successfully created EditTexts depending on the user input in Android, and also I have assigned them unique ID's using setId() method.

                  現(xiàn)在我要做的是在用戶點(diǎn)擊按鈕時從動態(tài)創(chuàng)建的 EditText 中獲取值,然后將它們?nèi)看鎯υ?String 變量中.即來自 EditText 的具有 id '1' 的值應(yīng)保存在 String 類型的 str1 中,依此類推,具體取決于 EditText 的數(shù)量.

                  Now what I want to do is to get values from the dynamically created EditTexts when the user tap a button, then store all of them in String variables. i.e. value from EditText having id '1' should be saved in str1 of type String, and so on depending on the number of EditTexts.

                  我正在使用 getid()gettext().toString() 方法,但這似乎有點(diǎn)棘手...我無法將 EditText 的每個值分配給一個字符串變量.當(dāng)我嘗試這樣做時,會發(fā)生 NullPointerException,如果不是沒有顯示用戶輸入數(shù)據(jù)的情況,我會在 toast 中顯示它.

                  I am using getid(), and gettext().toString() methods but it seems a bit tricky... I cannot assign each value of EditText to a String variable. When I try to do that a NullPointerException occurs, and if it is not the case where no user input data is shown, I display it in a toast.

                  這里,代碼:

                  EditText ed;
                  
                  for (int i = 0; i < count; i++) {   
                  
                          ed = new EditText(Activity2.this);
                          ed.setBackgroundResource(R.color.blackOpacity);
                          ed.setId(id);   
                          ed.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                                  LayoutParams.WRAP_CONTENT));
                          linear.addView(ed);
                  
                  }
                  

                  我現(xiàn)在如何將每個 EditText 的值傳遞給每個不同的字符串變量?如果有人可以幫助提供示例代碼,那就太好了.

                  How do I now pass the value from each EditText to each different string variable? If some body could help with a sample code it would be nice.

                  推薦答案

                  在每次迭代中你都在重寫 ed 變量,所以當(dāng)循環(huán)結(jié)束時 ed 只指向您創(chuàng)建的最后一個 EditText 實(shí)例.

                  In every iteration you are rewriting the ed variable, so when loop is finished ed only points to the last EditText instance you created.

                  您應(yīng)該存儲對所有 EditTexts 的所有引用:

                  You should store all references to all EditTexts:

                  EditText ed;
                  List<EditText> allEds = new ArrayList<EditText>();
                  
                  for (int i = 0; i < count; i++) {   
                  
                      ed = new EditText(Activity2.this);
                      allEds.add(ed);
                      ed.setBackgroundResource(R.color.blackOpacity);
                      ed.setId(id);   
                      ed.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                              LayoutParams.WRAP_CONTENT));
                      linear.addView(ed);
                  }
                  

                  現(xiàn)在 allEds 列表保存對所有 EditTexts 的引用,因此您可以對其進(jìn)行迭代并獲取所有數(shù)據(jù).

                  Now allEds list hold references to all EditTexts, so you can iterate it and get all the data.

                  更新:

                  根據(jù)要求:

                  String[] strings = new String[](allEds.size());
                  
                  for(int i=0; i < allEds.size(); i++){
                      string[i] = allEds.get(i).getText().toString();
                  }
                  

                  這篇關(guān)于如何從 Android 中每個動態(tài)創(chuàng)建的 EditText 獲取數(shù)據(jù)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲為 int?)
                  <legend id='Yl5KM'><style id='Yl5KM'><dir id='Yl5KM'><q id='Yl5KM'></q></dir></style></legend>

                    <tbody id='Yl5KM'></tbody>
                2. <i id='Yl5KM'><tr id='Yl5KM'><dt id='Yl5KM'><q id='Yl5KM'><span id='Yl5KM'><b id='Yl5KM'><form id='Yl5KM'><ins id='Yl5KM'></ins><ul id='Yl5KM'></ul><sub id='Yl5KM'></sub></form><legend id='Yl5KM'></legend><bdo id='Yl5KM'><pre id='Yl5KM'><center id='Yl5KM'></center></pre></bdo></b><th id='Yl5KM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Yl5KM'><tfoot id='Yl5KM'></tfoot><dl id='Yl5KM'><fieldset id='Yl5KM'></fieldset></dl></div>
                    <bdo id='Yl5KM'></bdo><ul id='Yl5KM'></ul>
                  • <small id='Yl5KM'></small><noframes id='Yl5KM'>

                      <tfoot id='Yl5KM'></tfoot>

                            主站蜘蛛池模板: 成人国产精品一级毛片视频毛片 | 国产黄色免费网站 | 免费在线观看黄网站 | 最近日韩中文字幕 | 久久久国产一区二区三区 | 久久成人免费 | 日韩精品久久久久久 | 一区中文字幕 | 五月精品视频 | 日韩一区不卡 | 国产露脸对白88av | 国产九九av | 免费看的黄网站 | 最新av在线网址 | 人人爽人人草 | 性色综合 | 久久久久久久久久爱 | 国产精品国产精品国产专区不蜜 | 免费精品| 亚洲欧美在线视频 | 暴草美女 | 亚洲成人国产精品 | 精品国产乱码一区二区三 | 亚洲人成在线播放 | 成人在线免费 | 国产xxxx岁13xxxxhd | 69av网 | 国产精彩视频一区 | 成人在线视频一区 | 在线看片国产精品 | 亚洲成人动漫在线观看 | 亚洲成人自拍 | 99pao成人国产永久免费视频 | 免费成人国产 | 国产精品久久国产精品99 | 欧美一级做a爰片免费视频 国产美女特级嫩嫩嫩bbb片 | 久久成人免费 | 91色在线视频 | 亚洲网站在线播放 | 日韩在线精品视频 | 天堂一区二区三区 |