如何写在EditText上取得XML解析特定值写在、定值、EditText、XML

2023-09-04 04:39:12 作者:被噩梦吓醒

我发现这个教程这表明XML解析,但显示出第一个屏幕上的XML文件中的所有值,我想tomodify这个code,并添加edittextbox这表明我键入编辑文本supose这名I型只值属性编辑文本框2所以在屏幕上显示唯一的ID 2 atttributes并非所有的数据在屏幕上显示我是如何连接的EditText框,数据库等是在屏幕上显示?唯一入选的项目。

i found this tutorial which show xml parsing but is show all values in xml file on 1st screen i want tomodify this code and add edittextbox which show only that value attributes which name i type on edit textbox supose i type in edit text box 2 so is show on screen only ID 2 atttributes not all data show on screen how i connect edittext box with database so is show only selected item on screen??

http://www.androidhive.info/2011/11 / Android的XML解析 - 教程/

推荐答案

是的,你可以在下面的code部分:

Yes you can , in the code section below :

for (int i = 0; i < nl.getLength(); i++) {
        // creating new HashMap
        HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element) nl.item(i);

        if(parser.getValue(e, KEY_ID).equals(et.getText().toString())){
        // adding each child node to HashMap key => value
        map.put(KEY_ID, parser.getValue(e, KEY_ID));
        map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
        map.put(KEY_COST, "Rs." + parser.getValue(e, KEY_COST));
        map.put(KEY_DESC, parser.getValue(e, KEY_DESC));

        // adding HashList to ArrayList
        menuItems.add(map);
}else{
 }

正如你所看到的,你只是检索XML中的ID,并将其与你在编辑文本获得ID。如果它们匹配其添加到HashMap中其他不!

As you can see , you just retrieve the id from XML and compare it to the id you get from the Edit text. If they match add it to the hashmap else dont !

希望这有助于!