通过图像按钮单击反转完整listView项目的任何可能方法
我有一个ListView
,它按顺序1-2-3-4-5-6-7-8-9-10
显示一个列表。我想要的是,当点击ImageButton
时,列表应以10-9-8-7-6-5-4-3-2-1
的形式显示其对象。
示例 -
伦敦
纽约
波士顿新泽西州
In 的形式
新泽西州的波士顿
纽约市的士郎
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;
}
}
答案 0 :(得分:2)
您可以使用length
并通知您的Collections.reverse(mArrayList);
,以便将其撤销。
答案 1 :(得分:2)
您所要做的就是撤消使用
填充列表视图的arraylist// *-----------------------*
// | MAIN-APP COMPONENT |
// *-----------------------*
import React, { Component } from "react";
import { Col, Well, Panel } from "react-bootstrap";
import { Route, Switch } from "react-router-dom";
import SideNavComponent from "./SideNavComponent";
const HomeComponent = () => <div>Home</div>;
const GraphComponent = () => <div>Graph</div>;
const DeviceComponent = () => <div>Device</div>;
const TransformationComponent = () => <div>Transformation</div>;
class App extends Component {
render() {
return (
<div>
<div className="header" />
<div className="body">
<Col md={3}>
<Well>
<SideNavComponent />
</Well>
</Col>
<Col md={9}>
<Panel>
<Switch>
<Route path="/device" component={DeviceComponent} />
<Route path="/transform" component={TransformationComponent} />
<Route path="/graph" component={GraphComponent} />
<Route exact path="/" component={HomeComponent} />
</Switch>
</Panel>
</Col>
</div>
<div className="footer" />
</div>
);
}
}
export default App;
// *-----------------------*
// | SIDENAV-COMPONENT |
// *-----------------------*
import React, { Component } from "react";
import { Nav, NavItem } from "react-bootstrap";
import { Link } from "react-router-dom";
class SideNavComponent extends Component {
render() {
return (
<div style={{ flexDirection: "column" }}>
<Link to="/">Home</Link>
<Link to="/graph">Graphs</Link>
</div>
);
}
}
export default SideNavComponent;
// *-----------------------*
// | MAIN.JS (ENTRY POINT) |
// *-----------------------*
import React from 'react'
import { render } from 'react-dom'
import App from './components/App';
import { BrowserRouter } from 'react-router-dom';
render((
<BrowserRouter>
<App />
</BrowserRouter>
), document.getElementById('root'));
然后调用适配器的Collections.reverse(aList);
方法。