我正在开发一个SQLite项目的Codename,当我遇到一些问题时,我正在尝试当我点击日历上的某个特定日期然后它将检查数据库中是否存在该日期,但是当我首先在应用程序启动后单击特定日期它会准确出现该日期,但是第二次将上一个日期出现添加到当前日期并显示其总和。那我怎么解决呢?
以下是我的代码: -
public class Customised extends Calendar{
ArrayList<String[]> data = new ArrayList<>();
public Customised(){
}
@Override
protected void updateButtonDayDate(Button dayButton, int currentMonth, int day) {
dayButton.setText(""+day);
dayButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try{
cur = db.executeQuery("SELECT Date from CalendarData WHERE Date = ? ", dateLabel.getText());
int columns = cur.getColumnCount();
if(columns > 0) {
boolean next = cur.next();
if(next) {
String[] columnNames = new String[columns];
for(int iter = 0 ; iter < columns ; iter++) {
columnNames[iter] = cur.getColumnName(iter);
}
while(next) {
Row currentRow = cur.getRow();
String[] currentRowArray = new String[columns];
for(int iter = 0 ; iter < columns ; iter++) {
currentRowArray[iter] = currentRow.getString(iter);
}
data.add(currentRowArray);
next = cur.next();
}
Object[][] arr = new Object[data.size()][];
data.toArray(arr);
}
}
}catch(IOException e){
e.printStackTrace();
}
int i;
for( i = 0 ; i< data.size(); i++){
Log.p(data.get(i)[0]);
}
Label a = new Label(dateLabel.getText());
Label b = new Label(""+i);
Container container1 = TableLayout.encloseIn(2, a,b);
calendar.add(container1);
Util.cleanup(data);
// dayButton.getAllStyles().setBgColor(0xef5555);
// dayButton.setText("* "+day);
}
});
}
@Override
protected Button createDay() {
Button day = new Button();
day.setAlignment(CENTER);
day.setUIID("CalendarDay");
day.setEndsWith3Points(false);
day.setTickerEnabled(false);
return day;
}
}
}
答案 0 :(得分:1)
我得到了这个问题的答案: -
@Override
protected void updateButtonDayDate(Button dayButton, int currentMonth, int day) {
dayButton.setText(""+day);
dayButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try{
cur = db.executeQuery("SELECT Date from CalendarData WHERE Date = ? ", dateLabel.getText());
int columns = cur.getColumnCount();
if(columns > 0) {
boolean next = cur.next();
if(next) {
String[] columnNames = new String[columns];
for(int iter = 0 ; iter < columns ; iter++) {
columnNames[iter] = cur.getColumnName(iter);
}
while(next) {
Row currentRow = cur.getRow();
String[] currentRowArray = new String[columns];
for(int iter = 0 ; iter < columns ; iter++) {
currentRowArray[iter] = currentRow.getString(iter);
}
data.add(currentRowArray);
next = cur.next();
}
Object[][] arr = new Object[data.size()][];
data.toArray(arr);
}
}
}catch(IOException e){
e.printStackTrace();
}
for( i = 0 ; i< data.size(); i++){
Log.p(data.get(i)[0]);
}
Label a = new Label(dateLabel.getText());
Label b = new Label(""+i);
Container container1 = TableLayout.encloseIn(2, a,b);
if(calendar.contains(container1)== true){
calendar.removeComponent(container1);
calendar.add(container1);
}else{
calendar.add(container1);
}
data.clear();
// dayButton.getAllStyles().setBgColor(0xef5555);
// dayButton.setText("* "+day);
}
});
}
感谢您的回复。