編輯:關於Android編程
廢話不多說了直接上代碼:
新建一個Xml文件用於讀取:
test.xml
後台:java Eclipse Swift Xcode C# Visual Studio
import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import java.io.IOException; import java.io.StringWriter; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; public class MainActivity extends ActionBarActivity { private TextView tv1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv1= (TextView) findViewById(R.id.tv1); try { //讀取與解析Xml文件: DocumentBuilderFactory builderFactory=DocumentBuilderFactory.newInstance(); DocumentBuilder builder=builderFactory.newDocumentBuilder(); Document document=builder.parse(getAssets().open("test.xml")); //記住導的是import org.w3c.dom.Document;不要導錯 Element element=document.getDocumentElement(); NodeList list=element.getElementsByTagName("lan");//過濾讀取lan所對應的內容 for (int i=0;i// java //Eclipse // lan1.setAttribute("id","1"); Element name1=newxml.createElement("name"); name1.setTextContent("java"); Element ide1=newxml.createElement("ide"); ide1.setTextContent("Eclipse"); lan1.appendChild(name1); lan1.appendChild(ide1); languages.appendChild(lan1); //// Element lan2=newxml.createElement("lan"); lan2.setAttribute("id", "1"); Element name2=newxml.createElement("name"); name2.setTextContent("Swift"); Element ide2=newxml.createElement("ide"); ide2.setTextContent("Xcode"); lan2.appendChild(name2); lan2.appendChild(ide2); languages.appendChild(lan2); newxml.appendChild(languages); TransformerFactory transformerFactory=TransformerFactory.newInstance(); Transformer transformer=transformerFactory.newTransformer(); transformer.setOutputProperty("encoding", "utf-8"); StringWriter sw=new StringWriter(); transformer.transform(new DOMSource(newxml),new StreamResult(sw)); sw.toString();//輸出查看結果 sw.close(); tv1.append("\n輸出結果:"+sw.toString()); } catch (IOException e) { e.printStackTrace(); Log.i("e1",e.toString()); } catch (ParserConfigurationException e) { e.printStackTrace(); Log.i("e2", e.toString()); } catch (SAXException e) { e.printStackTrace(); Log.i("e3", e.toString()); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } } }Swift //Xcode //
Android基礎入門教程——2.4.8 ListView Item多布局的實現標簽(空格分隔): Android基礎入門教程本節引言: 本節是L
CheckBox (多選) extends ButtoncheckBox中選擇器 state_checked : 已經被選中了 state_checkable: 可以被選
跟著代碼看一看豆瓣開源的混合開發框架Rexxaar // 初始化rexxar Rexxar.initialize(this);
Android藍牙串口通訊 閒著無聊玩起了Android藍牙模塊與單片機藍牙模塊的通信,簡單思路就是要手機通過藍牙發送控制指令給單片機,並作簡單的控制應用。單片機的藍牙