【发布时间】:2013-04-06 00:50:39
【问题描述】:
在我的应用程序中,我有一个 TextView,当用户第一次点击它时,我必须按降序排列数据,当用户再次点击相同的文本视图时,我必须按升序排列数据.有没有办法做到这一点?
我的代码:
public void onClick(View v) {
// TODO Auto-generated method stub
boolean flag = false;
db.open();
Cursor c;
if(flag==false)
{
c = db.getIncomeTitleDescitem(intent.getStringExtra("grpsdb"));
startManagingCursor(c);
flag=true;
}
else
{
System.out.println("inside else");
c = db.getIncomeTitleAscitem(intent.getStringExtra("grpsdb"));
startManagingCursor(c);
flag=false;
}
ListView lv=(ListView)findViewById(R.id.listView1);
String[] fromdes = new String[] {db.KEY_DATE,db.KEY_DESC,db.KEY_INCOME,db.KEY_TOTAL};
int[] todes = new int[] {R.id.text1 ,R.id.text3,R.id.text5,R.id.text7};
SimpleCursorAdapter notes = new SimpleCursorAdapter(IncomeDetails.this, R.layout.columnview, c, fromdes, todes);
lv.setAdapter(notes);
db.close();
}
【问题讨论】:
-
检查一下我认为这个答案适合你的问题stackoverflow.com/questions/7837601/…
-
数据你的意思是TextView的文本???
-
哦,为什么要在 onClick 中创建布尔标志,它将继续创建,只创建一次..