2011-08-15 6 views
0

이 코드를 사용하여 HTML 페이지에서 요소를 검색합니다.안드로이드에있는 ListView에 요소를 넣는 방법?

// Get all td's that are a child of a row - each game has 4 of these 
Elements games = doc.select("tr > td.indexList1, tr > td.indexList2"); 

// Iterator over those elements 
ListIterator<Element> gameIt = games.listIterator(); 

while (gameIt.hasNext()) { 
// Get the title of the game 
Element title = gameIt.next(); 

System.out.println(title.text()); 

// Unneeded elements 
Element platform = gameIt.next(); 
Element genre = gameIt.next(); 

// Get the release date of the game 
Element release = gameIt.next(); 
System.out.println(release.text() + "\[email protected]@@@@@"); 
} 

어떻게하면 ListView에 title 요소에 대한 두 textviews와 release 요소에 대한 두 요소가 추가 될까요? 다음은 나에게이 오류

08-15 14:49:37.730: ERROR/AndroidRuntime(18945): FATAL EXCEPTION: main 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945): android.content.res.Resources$NotFoundException: Resource ID #0x7f050001 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.content.res.Resources.getValue(Resources.java:1014) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:2049) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.content.res.Resources.getLayout(Resources.java:853) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.view.LayoutInflater.inflate(LayoutInflater.java:389) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:375) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.widget.ArrayAdapter.getView(ArrayAdapter.java:366) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.widget.AbsListView.obtainView(AbsListView.java:1970) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.widget.ListView.measureHeightOfChildren(ListView.java:1228) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.widget.ListView.onMeasure(ListView.java:1139) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.view.View.measure(View.java:10828) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:613) 
08-15 14:49:37.730: ERROR/AndroidRuntime(18945):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:519) 

을 편집은-제공

는리스트 뷰는 항목에서 떨어져 자신을 추출하기 때문에 실제 항목에 대한 ListAdapter을 의미한다

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<TextView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/outputTextView" 
/> 
<ListView android:layout_height="wrap_content" android:id="@+id/list" android:layout_width="match_parent"></ListView> 
</LinearLayout> 
+0

의 중복 가능성 (http://stackoverflow.com/questions/7065756/how-to- load-these-elements-to-populate-a-list-in-android) – bmargulies

+0

제대로 작동하지 않아 대답이 혼란 스럽습니다. –

답변

1

내 XML 레이아웃입니다.

ListAdapter에 실제 항목을 넣은 다음 ListView를 호출해야합니다. (ListAdapter yourListAdapter)입니다. 다음과 같은 조건이 같은

+0

예제를 제공해 주시겠습니까? –

+0

ListView에 대한이 [자습서] (http://www.vogella.de/articles/AndroidListView/article.html)를 살펴 보시기 바랍니다. 이 웹 사이트에는 편리한 튜토리얼 세트가 있습니다. –

+0

또한 Android SDK에는 찾고자하는 것을 포함하여 다양한 종류의 목록을 구현하는 방법의 예가 있습니다. –

2

뭔가 : 당신은 ListActivity

  • 를 사용하는

    1. 당신은 게임에 대한 POJO를 만들 수 있습니다.

    번호 : [? 안드로이드의 목록을 채우는 이러한 요소를로드하는 방법]

    List<Game> games = new ArrayList<Game>(); 
    while (gameIt.hasNext()) { 
    
        // Get the title of the game 
        Element title = gameIt.next(); 
    
        // Unneeded elements 
        Element platform = gameIt.next(); 
        Element genre = gameIt.next(); 
    
        // Get the release date of the game 
        Element release = gameIt.next(); 
    
        Game game = new Game(title, platform, genre, release); 
        games.add(game); 
    } 
    
    ArrayAdapter adapter = new ArrayAdapter<Game>(this, R.id.YOUR_LIST_ITEM_VIEW, games); 
    setListAdapter(adapter); 
    
  • +0

    위의 편집을보십시오. 오류가 발생했습니다. 내 레이아웃이 잘못되었다고 생각합니다. –

    +1

    [Please RTFM] (http://developer.android.com/resources/tutorials/views/hello-listview.html) –

    관련 문제