3

Linearlayout 内に ListView があります。リストビューにはカスタムのカーソルアダプターがあります。ListView がスクロールしないことを除いて、すべて正常に動作します。

どんな提案でも大歓迎です!! ありがとう。マウリツィオ

MainActivity の XML は次のとおりです。

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

関連するJavaコードは次のとおりです。

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(); }
        });
}
4

3 に答える 3

11

ListViews Layout パラメータは「wrap_content」です。litview に新しいアイテムを追加すると、展開されます。したがって、スクロールしません。「match_parent」に設定すると、必ずスクロールが開始されます。また、コンテンツ(子ビューが何であれ)のサイズがそれよりも大きい場合にのみ、ビューがスクロールすることを忘れないでください。

于 2012-11-26T12:52:23.863 に答える
3

高さを超えるリスト アイテムを追加します。その後、スクロールできます。

于 2012-11-26T12:49:27.113 に答える
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>
于 2012-11-26T12:51:16.743 に答える