android listview无法滚动,android – ListView不滚动.我如何解决它?

纪枫
2023-12-01

我在Linearlayout中有一个ListView.

listview有一个自定义的cursoradapter.

一切正常,但ListView不滚动.

任何建议超过欢迎!!谢谢.毛里齐奥

这是MainActivity的XML

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

android:id="@+id/buttonAdd"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:gravity="center_horizontal"

android:text="Aggiungi" />

android:id="@+id/list"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

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

});

}

解决方法:

ListViews布局参数是“wrap_content”.当您向litview添加新项目时,它将展开.因此它不会滚动.如果你把它设置为“match_parent”它肯定会开始滚动.并且不要忘记一个视图只在其内容(孩子们查看了什么)时滚动

尺寸比它大.

标签:android,scroll,listview

来源: https://codeday.me/bug/20190713/1450504.html

 类似资料: