그래서 저는 인터넷 검색을하고, 어리석은 감독이라고 생각하는 답변을 찾아 보았습니다.Android : ListView에 항목이 표시되지 않고 채워져 있음을 알 수 있습니다.
저는 ArrayAdapter
으로 채우는 ListView
을 가지고 있습니다. 이는 내 응용 프로그램의 다른 곳에서 사용하고있는 객체 목록을 구축하고 있습니다. 나는 getCount
을 통해 .setAdapter()
으로 전화하기 전과 후에 모두 어댑터에 항목이 있는지 확인했습니다. 그러나 내 응용 프로그램에 아무것도 나타나지 않습니다.
내 주요 레이아웃 res/layout/playlistview
는 각 항목 res/layout/singlelistitem
에 대한
textview
을
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/playlist_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#80000000"
android:gravity="center"
android:orientation="horizontal" >
<ListView
android:id="@+id/playlistview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#206"
android:background="#602" >
</ListView>
</LinearLayout>
(I 더 쉽게에 무슨 일이 일어나고 있는지 볼 수 있도록 나는 색상을 설정) :
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/single_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:padding="5dp"
android:background="#206">
</TextView>
및 그것을 채우기 위해 사용하는 코드 :
private ListView playlistView;
private void buildPlaylistView() {
playlistView = (ListView)findViewById(R.id.playlistview);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.singlelistitem, R.id.single_item, playlist.titlesAsArray());
playlistView.setAdapter(adapter);
playlistView.setVisibility(View.VISIBLE);
adapter.notifyDataSetChanged();
((ArrayAdapter<String>)playlistView.getAdapter()).notifyDataSetChanged();
}
playlist.titlesAsArray()
은 String[]
을 반환하며 작동합니다.
내가 그걸 발견하고 그걸 시도했기 때문에 나는 둘 다 .notifyDataSetChanged()
을 가지고있다. 내가 wrap_content
내 XML에 ListView
객체의 android:layout_height
을 변경하면
, 나는 그것을 감싸는 LinearLayout
에 오직 불투명 한 배경을 참조하십시오. ListView
android:layout_height
을 match_parent
으로 설정하면 전체 화면이 #206
(magentish)입니다.
setAdapter()
전에 어댑터에서 getCount()
을 확인하면 항목이 있다고합니다. 보기 후에 그 항목을 확인하면 같은 수의 항목이 있다고합니다. 나는 이것에 완전히 분실되었지만 아무것도 표시되지 않습니다.
방금 확인했는데 정상적으로 작동합니다. 나는'buildPlaylistView(); '를 호출하고 그 내용 및/또는 어댑터를 효과적으로 재설정 한 후에 다른 것이'playlistView'를 망친다 고 생각합니다. 게시 한 코드에 포함되지 않았습니다. – andr
내가 playlistView 전역에하는 유일한 일은 bringToFront()를 호출하고 아무 것도하지 않는다는 것입니다. id/playlist_screen (외부 레이아웃)에 연결된보기에서 표시 여부를 설정하고 무효화하여 다시 그리기를 강제하고 일부 애니메이션을 수행합니다. – Kimo
음 ... 나도 몰라. 가능한 경우 전체 프로젝트를 업로드하십시오. 그것이 없다면 그것은 단지 추측 일뿐입니다. 내가 말했듯이 - 정적 데이터를 반환하기 위해'playlist.titlesAsArray()'를 조롱하고 실제 장치에서 실행하면 벌금이 부과됩니다. 괜찮 으면, 적절한 색상 등으로 어댑터의 모든 항목을 보여줬다는 것을 의미합니다. 더 많은 힌트를 제공 할 수도 있습니다. 어떤 API를 사용하고 있습니까? 에뮬레이터 또는 장치에서 이것을 실행하고 있습니까? 모든 것이 여기에 중요 할 수 있습니다 ... – andr