2012-11-26 4 views
3

선형 뷰 내부에 ListView가 있습니다. listview에는 사용자 정의 cursoradapter가 있습니다. ListView가 스크롤되지 않는 것을 제외하면 모든 것이 잘 작동합니다.ListView가 스크롤되지 않습니다. 어떻게 수정해야합니까?

어떤 제안이라도 환영합니다! 감사.

마우리 치오

다음은 여기에 자바 코드의 관련 부분이다 MainActivity

<?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" > 

    <Button 
     android:id="@+id/buttonAdd" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="Aggiungi" /> 

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

</LinearLayout> 

의 XML입니다.

public class MainActivity extends Activity { 
    private DatabaseHelper db=null; 
    private Cursor tabellaCursor=null; 
    private ListAdapter adapter; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     int[] to = new int[] {R.id.name_entry}; 
     db = new DatabaseHelper(this); 
     tabellaCursor=db.getWritableDatabase().rawQuery("SELECT _id, colonna1, colo  nna2, colonna3 FROM tabella ORDER BY _id", null); 
     ListAdapter adapter=new MyAdapter(this, R.layout.list_example_entry, tabe  llaCursor, new String[]{"colonna1"},to); 
     ListView lt = (ListView)findViewById(R.id.list); 
     lt.setAdapter(adapter); 
     Button addbtn=(Button)findViewById(R.id.buttonAdd); 
     addbtn.setOnClickListener(new OnClickListener() 
     {public void onClick(View v){add(); } 
     }); 
} 

답변

9

ListViews 레이아웃 매개 변수는 "wrap_content"입니다. 그것은 당신이 새로운 항목을 조명보기에 추가함에 따라 확장 될 것입니다. 따라서 스크롤하지 않습니다. "match_parent"로 설정하면 스크롤링을 시작하게됩니다. 그 내용 (차일드가 무엇을 보았는지) 크기가 큰 경우에만보기가 스크롤된다는 것을 잊지 마십시오.

+0

맞아요, 항목을 추가하면 스크롤됩니다. –

+0

관련이 없지만 올바른 방향으로 나를 잡았다. 나는 물건이 많다고 생각했다. 목록에 있지만 2 개가 있었고 예, 스크롤하지 않았습니다 .. 10 개의 항목을 추가 한 후. 나는 그것이 올바르게 스크롤되는 것을 보았다. – reidisaki

3

높이를 초과하는 목록 항목을 추가하십시오. 그러면 스크롤 할 수 있습니다.

3

다음 코드를 사용하여 문제를 해결하십시오.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <Button 
     android:id="@+id/buttonAdd" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="Aggiungi" /> 

    <ListView 
     android:id="@+id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/buttonAdd"/> 

</RelativeLayout> 
관련 문제