만들려는 어플이 있는데 책보고 그대로 따라하는데 안나옵니다.ㅠㅜ 안드로이드 기초와 실전앱프로젝트 책 내용입니다.
첫화면에 리스트뷰에 웹서버에있는 food_list.xml 에 있는 내용을 받아와서 뿌려줘야하는데 흰화면만 나오네요 ㅜ
layout 폴더 안에 activity_main.xml list_row.xml detail.xml
src 폴더 안에 MainActivity.java
cmsHTTP.java(웹통신 클래스)
NetworkXMLActivity.java
이렇게 구성되어 있습니다.
웹서버에서 받아와야하는데..그냥 위에 소스만 가지고 컴파일하면 나와야하는게 아닌건가요?
따로 뭐 설정을 해줘야하나요? 리스트뷰에 나올 리스트는 http://www.owllab.com/android2/food_list.xml
에서 받아옵니다.
익스플로러에서 위에 주소 들어가보면 사진이나 글은 나오던데..왜 리스트뷰에 안나올까요 ㅜ
뭔가 연동하는 부분이 있어야될거같기도 한데...
어플은 처음만들어보고 웹서버에 대한 지식도 전무해서 뭘 어떻게 해야할지 모르겠어요 ㅠ 뭐가 문제일까요?
아래는 소스입니다.
-----------------------------------------------------------------------------
[activity_main.xml]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/button1" android:layout_height="wrap_content"
android:layout_width="match_parent" android:text="제 목"
android:onClick="reLoadList"></Button>
<ListView
android:layout_height="350dp" android:id="@+id/listView1"
android:layout_width="match_parent"
></ListView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<Button android:id="@+id/button2" android:layout_height="wrap_content" android:layout_weight="1"
android:layout_width="wrap_content" android:text="버튼 1"
></Button>
<Button android:id="@+id/button3" android:layout_height="wrap_content" android:layout_weight="1"
android:layout_width="wrap_content" android:text="버튼 2"
></Button>
</LinearLayout>
</LinearLayout>
-----------------------
[cmsHTTP.java]
package com.owl.test4;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import android.app.Activity;
import android.util.Log;
import android.widget.Toast;
public class cmsHTTP {
public String mimeType = "text/html";
public String encoding = "UTF-8";
public int REGISTRATION_TIMEOUT = 10 * 1000;
public String TAG = "cmsHTTP";
public Activity act;
public String noData = "네트워크 장애 \n다시 시도해주세요";
public cmsHTTP(){
}
public String sendGet(String url){
String result=null;
HttpResponse resp;
HttpGet httpGet = new HttpGet(url);
HttpClient httpClient = new DefaultHttpClient();
HttpParams tmpparms = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(tmpparms,REGISTRATION_TIMEOUT);
HttpConnectionParams.setSoTimeout(tmpparms,REGISTRATION_TIMEOUT);
ConnManagerParams.setTimeout(tmpparms,REGISTRATION_TIMEOUT);
try{
resp = httpClient.execute(httpGet);
if(resp.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
if(Log.isLoggable(TAG,Log.VERBOSE))
Log.v(TAG,"Successful authentication");
HttpEntity respEntity = resp.getEntity();
if(respEntity != null){
InputStream instream = respEntity.getContent();
result = convertStreamToString(instream);
instream.close();
}
}else{
if(Log.isLoggable(TAG,Log.VERBOSE))
Log.v(TAG,"Error Process"+ resp.getStatusLine());
}
}catch(final IOException e){
if(Log.isLoggable(TAG, Log.VERBOSE))
Log.v(TAG, "IOException when getting authtoken",e);
}finally{
if(Log.isLoggable(TAG,Log.VERBOSE))
Log.v(TAG,"completing");
}
if(result==null){
Toast.makeText(act, noData, Toast.LENGTH_SHORT).show();
}
return result;
}
public String convertStreamToString(InputStream is){
StringBuilder sb = new StringBuilder();
String line = null;
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,encoding),8);
while((line=reader.readLine())!=null){
sb.append(line + "\n");
}
}catch(IOException e){
e.printStackTrace();
}finally{
try{
is.close();
}catch(IOException e){
e.printStackTrace();
}
}
return sb.toString();
}
}
-----------------------------