我是android的新手,在编程方面不是一个杀手。我正在尝试实现一个动态列表视图,其中必须将项添加到顶部,而不是默认情况下添加到底部。有没有办法做到这一点?下面是我用来创建动态列表视图的代码。请帮帮我!
private void populateListView() {
Cursor cursor = myDb.getAllRows();
startManagingCursor(cursor);
String[] fromFieldNames = new String[]
{DBadapter.KEY_FIELD1,DBadapter.KEY_FIELD2};
int[] toViewIDs = new int[]
{R.id.field1,R.id.field2};
SimpleCursorAdapter myCursorAdapter =
new SimpleCursorAdapter(
this,
R.layout.inner_list_view,
cursor,
fromFieldNames,
toViewIDs
);
ListView myList = (ListView) findViewById(R.id.sampleList);
myList.setAdapter(myCursorAdapter);
myCursorAdapter.notifyDataSetChanged();
}发布于 2014-12-18 10:01:15
ListViews支持从底部堆叠项目。您可以使用android:stackFromBottom在XML中设置它,也可以通过调用setStackFromBottom(boolean)以编程方式设置它。
我不明白你问题的第二部分。
发布于 2015-08-30 15:59:31
您可以使用"insert“方法。它允许您定义添加新项目的位置
myCursorAdapter.insert(newItem, 0);如果有多个元素,请使用循环
https://stackoverflow.com/questions/27532967
复制相似问题