xml dosyamı logcatte görüntüledim adtde görüntülemiyorum
public class MainActivity extends Activity {
String Url="http://192.168.2.2:8886/menü";
EditText etResponse;
TextView textview;
NodeList nodelist;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_item);
textview = (TextView) findViewById(R.id.text1);
// get reference to the views
new HttpAsyncTask().execute(Url);
}
public static String GET(String url){
InputStream inputStream = null;
String result = "";
try {
// create HttpClient
HttpClient httpclient = new DefaultHttpClient();
// make GET request to the given URL
HttpResponse httpResponse = httpclient.execute(new HttpGet(url));
// receive response as inputStream
inputStream = httpResponse.getEntity().getContent();
// convert inputstream to string
if(inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}
return result;
}
private static String convertInputStreamToString(InputStream inputStream) throws IOException{
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
String line = "";
String result = "";
while((line = bufferedReader.readLine()) != null)
result += line;
inputStream.close();
return result;
}
private class HttpAsyncTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
try {
URL url = new URL(urls[0]);
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
// Download the XML file
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
// Locate the Tag Name
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
nodelist = doc.getElementsByTagName("row");
System.out.println("Number of row nodes: " + nodelist.getLength());
for (int temp = 0; temp < nodelist.getLength(); temp++)
{ Node nNode = nodelist.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nodelist.item(temp);
nodelist = doc.getElementsByTagName("row");
String urunName = eElement.getAttribute("urunismi");
System.out.println("Ürünismi: " + urunName);
System.out.println("-----------------------");
}}
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return GET(urls[0]);
}
// onPostExecute displays the results of the AsyncTask.
protected void onPostExecute(String result) {
Log.d("onPostExecute Serviço", result);
}
}
}