【问题标题】:Inverting the whole list in a listView在 listView 中反转整个列表
【发布时间】:2017-08-05 16:26:21
【问题描述】:

通过单击图像按钮来反转完整列表视图项的任何可能方式。
我有一个ListView,它按1-2-3-4-5-6-7-8-9-10 的顺序显示一个列表。我想要的是,当单击ImageButton 时,列表应以10-9-8-7-6-5-4-3-2-1 的形式显示其对象。
示例-

伦敦
纽约
波士顿
新泽西

形式为
新泽西
波士顿
纽约
伦敦

MainActivity.java

        db = new MyDatabase(this);
        employees = db.getEmployees(); 
        final ListAdapter adapter = new SimpleCursorAdapter(this,
                android.R.layout.simple_list_item_1,
                employees,
                new String[] {"Name"},
                new int[] {android.R.id.text1});    
        final ListView listView = (ListView) findViewById(R.id.listV2);
        listView.setAdapter(adapter);

MyDatabase.java

public class MyDatabase extends SQLiteAssetHelper {

    private static final String DATABASE_NAME = "plethora.db";
    private static final int DATABASE_VERSION = 1;

    public MyDatabase(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    public Cursor getEmployees() {

        SQLiteDatabase db = getReadableDatabase();
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

        String [] sqlSelect = {"2 _id", "Name"};
        String sqlTables = "DelhiBus";

        qb.setTables(sqlTables);
        Cursor c = qb.query(db, sqlSelect, null, null,
                null, null, null);

        c.moveToFirst();
        return c;

    }

}

【问题讨论】:

标签: android mysql sql database sqlite


【解决方案1】:

您所要做的就是反转正在使用您的列表视图填充的数组列表

Collections.reverse(aList);

然后调用适配器的notifyDataSetChanged()方法。

【讨论】:

    【解决方案2】:

    您可以使用Collections.reverse(mArrayList); 并通知您的Adapter,这样它就会被反转。

    【讨论】:

    • 请添加你的logcat
    • 我添加了 logcat。谢谢
    • 你正在反转 listView 你需要反转 ArrayList
    • 对不起,我没有添加代码。我已经添加了它。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-28
    • 2014-03-19
    相关资源
    最近更新 更多