2017-01-15 1 views
0
나는이 같은 XML에 ListView을 넣어

:안드로이드 스튜디오의 ListView 기본 항목

<ListView 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 

와 나는 MainActivity에서의 항목을 넣어하지 않은,하지만 이미 1에서 나에게 기본 항목을 제공합니다 8 스크린 샷과 마찬가지로 ArrayAdapterMainActivity에 사용해도 여전히 ListView은 변경되지 않습니다.

enter image description here

이에 어떤 도움을 주시면 감사하겠습니다.

+0

작성한 코드를 표시해야합니다. – surya

+0

어댑터 클래스가 있어야합니다. ArrayAdapter를 보여주세요. –

+0

여러분, 고맙습니다. 그냥 문제를 해결하십시오. 그것은 내가 애플 리케이션을 실행하는 핸드폰을 사용하여 밝혀 졌, 내가 일하는 올바른 ListView 보여줍니다. –

답변

0

게시 한 스크린 샷에 따라 목록보기가 제대로 초기화되지 않은 결과입니다.

레이아웃처럼 보일 것이다이

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context=".ListActivity" > 

    <ListView 
     android:id="@+id/mobile_list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
    </ListView> 

</LinearLayout> 

<?xml version="1.0" encoding="utf-8"?> 
<!-- Single List Item Design --> 

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/label" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="10dip" 
    android:textSize="16dip" 
    android:textStyle="bold" > 
</TextView> 
처럼 보일 것이다이

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class MainActivity extends Activity { 
    // Array of strings... 
    String[] mobileArray = {"Android","IPhone","WindowsMobile","Blackberry", 
     "WebOS","Ubuntu","Windows7","Max OS X"}; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     ArrayAdapter adapter = new ArrayAdapter<String>(this, 
     R.layout.activity_listview, mobileArray); 

     ListView listView = (ListView) findViewById(R.id.mobile_list); 
     listView.setAdapter(adapter); 
    } 
} 

그리고 당신의 목록보기 항목 레이아웃 리소스 파일 같은 것을 보여야 MainActivity

이것이 어떻게 작동하는지 이해하는 데 도움이됩니다. 더 확인하려면 https://www.tutorialspoint.com/android/android_list_view.htm

+0

감사합니다. 그냥 문제를 해결하십시오. 그것은 내가 애플 리케이션을 실행하는 핸드폰을 사용하여 밝혀 졌, 내가 일하는 올바른 ListView 보여줍니다. –

관련 문제