2
TextView 화면에 아무 것도 기록되지 않습니다.xml에서 정보를 가져 오지만 표시되지 않음
나는 내가 잘못 여기서 뭘하는지 모르겠지만이 내 다음 코드 :
<?xml version="1.0"?>
<news>
<article title="TITLE HERE" link="*.php?showtopic=118" date="DATE HERE"></article>
</news>
자바 코드 :
try {
//open an URL connection make GET to the server and
URL url = new URL("http://.../m_news.xml");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream is = conn.getInputStream();
//DocumentBuilderFactory, DocumentBuilder are used for
//xml parsing
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
//using db (Document Builder) parse xml data and assign
//it to Element
Document document = db.parse(is);
Element element = document.getDocumentElement();
NodeList nodeList = element.getElementsByTagName("news");
NodeList nodeList2 = element.getElementsByTagName("article");
if (nodeList.getLength() > 0) {
for (int i = 0; i < nodeList2.getLength(); i++) {
Element entry = (Element) nodeList.item(0);
Element _rowE = (Element) entry.getElementsByTagName("article").item(i);
Node _rowTITLE = _rowE.getAttributes().getNamedItem("title");
Node _rowLINK = _rowE.getAttributes().getNamedItem("link");
TextView textview = new TextView(this);
textview.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='"+_rowLINK.getNodeValue()+"'>"+_rowTITLE.getNodeValue()+"</a>";
textview.setText(Html.fromHtml(text));
setContentView(textview);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
방금 텍스트를 설정하려고 했나 :
그런 다음 코드는 다음을 포함하도록 변경
이있다 news.xml라는 간단한 레이아웃을 만드시겠습니까? – blindstuffUI 스레드에서 모든 작업을 수행하고 있다면 정말 나쁜 것입니다 ... – Falmarri
멋진 포켓몬 시도/캐치 :) – ocodo