我正在处理下面的代码,我在BlackBerry的Pane Manager中创建了3个选项卡。第一个选项卡允许用户根据客户名称选择日期范围,并获取该客户的结果,以网格格式显示在第三个选项卡中。
所以第一个选项卡有两个日期字段和一个客户文本字段,还有一个搜索按钮。
单击“搜索”按钮时,它将选择搜索记录并跳到第三个选项卡以网格格式显示。
第三个选项卡有try catch语句,用于逐字符串将表记录元素插入到网格中。
现在的问题是我一打开我的应用程序,单击第三个选项卡,它就会显示充满垃圾值的网格。它不会等待单击第一个选项卡的搜索按钮,然后显示结果。如果我碰巧关闭了应用程序并重新打开它,我会发现第三个选项卡显示了我上一次搜索的结果。
代码如下:
// setup the tab model with 3 tabs
final PaneManagerModel model = new PaneManagerModel();
model.enableLooping( true );
// setup the first tab XXXXXXXXXXXXXXXXXXXX~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VerticalFieldManager vfm = new VerticalFieldManager(
Field.USE_ALL_HEIGHT | Field.USE_ALL_WIDTH |
Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL );
LabelField lbl = new LabelField( "Content for tab 1", Field.FOCUSABLE );
vfm.add( lbl );
TextField1 = new TextField(" Name: ",null)
{
protected boolean keyChar(char ch, int status, int time)
{
if (CharacterUtilities.isLetter(ch) || (ch == Characters.BACKSPACE || (ch == Characters.SPACE)))
{
return super.keyChar(ch, status, time);
}
return true;
}
};
vfm.add(TextField1);
SimpleDateFormat sdfDate = new SimpleDateFormat("dd/MM/yyyy");//dd/MM/yyyy
Date now = new Date();
String strDate = sdfDate.format(now);
TextField2 = new TextField("\n From: ",strDate);
vfm.add(TextField2);
// TextField3 = new TextField("TO: ",null);
//vfm.add(TextField3);
SimpleDateFormat sdfDate1 = new SimpleDateFormat("dd/MM/yyyy");//dd/MM/yyyy
Date later = new Date();
String strDate1 = sdfDate1.format(later);
TextField3 = new TextField("\n To: ",strDate1);
vfm.add(TextField3);
ButtonField showInputButton = new ButtonField(" Search ",ButtonField.FIELD_HCENTER | ButtonField.CONSUME_CLICK);
showInputButton.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field,int context)
{
Dialog.alert(TextField1.getText());
try
{
//Open or create the database
Database db = DatabaseFactory.openOrCreate("database1.db");
//Insert onto table
Statement statement13 = db.createStatement("INSERT into
Temp4(date,bill,narration) VALUES (('"+TextField3.getText()+"'),(SELECT balance FROM Temp3),('Opening Balance'))");
statement13.prepare();
statement13.execute();
Statement statement131 = db.createStatement("INSERT INTO Temp4(date,bill,narration,id) select date,amount,narration,id from Bills where name=\'"+TextField1.getText()+"\' AND substr(date,7)||substr(date,4,2)||substr(date,1,2) < substr (\'"+TextField3.getText()+"\',7)||substr (\'"+TextField3.getText()+"\',4,2)||substr (\'"+TextField3.getText()+"\',1,2) ");
statement131.prepare();
statement131.execute(); // date INTEGER,bill INTEGER,rec INTEGER,narration TEXT,id INTEGER
statement131.close();
Statement statement132 = db.createStatement("INSERT INTO Temp4(date,rec,narration,id) select date,amount,narration,id from Receipts where name=\'"+TextField1.getText()+"\' AND substr(date,7)||substr(date,4,2)||substr(date,1,2) < substr (\'"+TextField3.getText()+"\',7)||substr (\'"+TextField3.getText()+"\',4,2)||substr (\'"+TextField3.getText()+"\',1,2) ");
statement132.prepare();
statement132.execute();
statement132.close();
db.close();
}
catch( Exception e )
{
System.out.println( e.getMessage() );
e.printStackTrace();
}
model.getView().jumpTo(2,PaneManagerView.DIRECTION_NONE);
}
}
);
vfm.add(showInputButton);
LabelField myLbl = new MyLabelField( "Ledger" );
NullField nullFld = new NullField( Field.FOCUSABLE );
HorizontalFieldManager hfm = new HorizontalFieldManager();
hfm.add( nullFld );
hfm.add( myLbl );
Pane pane = new Pane( hfm, vfm );
model.addPane( pane );
//Here ends tab 1 code
//设置第三个选项卡-xxxxxxxxxxxxxxxxxxxxxxxxxxxx~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vfm = new VerticalFieldManager(
Field.USE_ALL_HEIGHT | Field.USE_ALL_WIDTH |
Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL );
myLbl = new MyLabelField( "Daily Report" );
//Adding grid format for fetching from temp4 table----------------
final GridFieldManager grid = new GridFieldManager(10,5,0);
grid.add(new LabelField("Date")
{
public void paint(Graphics graphics)
{
graphics.setColor(Color.CYAN);
super.paint(graphics);
}
});
grid.add(new LabelField("Bill")
{
public void paint(Graphics graphics)
{
graphics.setColor(Color.CYAN);
super.paint(graphics);
}
});
grid.add(new LabelField("Receipt")
{
public void paint(Graphics graphics)
{
graphics.setColor(Color.CYAN);
super.paint(graphics);
}
});
grid.add(new LabelField("Narration")
{
public void paint(Graphics graphics)
{
graphics.setColor(Color.CYAN);
super.paint(graphics);
}
});
grid.add(new LabelField("ID")
{
public void paint(Graphics graphics)
{
graphics.setColor(Color.CYAN);
super.paint(graphics);
}
});
grid.setColumnPadding(20);
grid.setRowPadding(20);
//try catch was here
try
{
//Open or create the database
Database db = DatabaseFactory.openOrCreate("database1.db");
Statement statement55 = db.createStatement("CREATE TABLE IF NOT EXISTS Temp4(date INTEGER,bill INTEGER,rec INTEGER,narration TEXT,id INTEGER)");
statement55.prepare();
statement55.execute();
statement55.close();
Statement statement56 = db.createStatement("SELECT date,bill,rec,narration,id FROM Temp4 ORDER BY ROWID DESC");
statement56.prepare();
statement56.execute();
Cursor c = statement56.getCursor();
//Get to the row of grid
for (int i = 1; i < grid.getRowCount(); i++)
{
System.out.println("Inside for first loops");
//Get to the column of grid
for (int j = 0; j < grid.getColumnCount() ; j++)
{
System.out.println("Inside for second loops");
//Get to the row of temp4 table
while(c.next())
{
System.out.println("Inside while");
Row r;
r = c.getRow();
//Get to the column of temp4 table
for (int k = 4; k >=0; k--)
{
System.out.println("Inside for loops");
//Check for whether column retrieved is date or naraation
if(k==0 || k==3)
{
System.out.println("Retrieving date or narration");
grid.insert(new LabelField(r.getString(k))
{
public void paint(Graphics graphics)
{
graphics.setColor(Color.GOLD);
super.paint(graphics);
}
},i,j);
}
else
{
//Check for whether column retrieved is bills,rec or id
System.out.println("Retrieving other values");
String p = "" + r.getObject(k);
//if(r.getString(k) != null)
//{
grid.insert(new LabelField(p)
{
public void paint(Graphics graphics)
{
graphics.setColor(Color.GOLD);
super.paint(graphics);
}
},i,j);
// }
}
grid.setBackground(BackgroundFactory.createLinearGradientBackground(Color.MIDNIGHTBLUE,Color.STEELBLUE,Color.MIDNIGHTBLUE,Color.STEELBLUE));
//grid.setBackground(BackgroundFactory.createLinearGradientBackground(Color.GOLD,Color.CHOCOLATE,Color.GOLDENROD,Color.CORAL));
}
System.out.println("Exiting while");
}
System.out.println("Exiting sec for");
break;
}
System.out.println("Exiting first for");
break;
}
statement56.close();
db.close();
}
catch( Exception e )
{
System.out.println( e.getMessage() );
e.printStackTrace();
}
vfm.add(grid);
//----------------grid ends----------------------------------------
nullFld = new NullField( Field.FOCUSABLE );
hfm = new HorizontalFieldManager();
hfm.add( nullFld );
hfm.add( myLbl );
pane = new Pane( hfm, vfm );
model.addPane( pane );
现在剩下的部分
// select the tab to be displayed
model.setCurrentlySelectedIndex( 0 );
// setup the rest of the components
HorizontalTabTitleView titleView = new HorizontalTabTitleView( Field.FOCUSABLE );
titleView.setNumberOfDisplayedTabs( 3 );
titleView.setModel( model );
PaneView paneView = new PaneView( Field.FOCUSABLE );
paneView.setModel( model );
PaneManagerView view = new PaneManagerView(
Field.FOCUSABLE | Manager.NO_VERTICAL_SCROLL |
Manager.NO_HORIZONTAL_SCROLL | Manager.USE_ALL_HEIGHT |
Manager.USE_ALL_WIDTH,
titleView, paneView );
view.setModel( model );
model.setView( view );
// configure the Controller
HorizontalTabController controller = new HorizontalTabController();
controller.setModel( model );
controller.setView( view );
model.setController( controller );
view.setController( controller );
// add the tab manager to the MainScreen
this.add( view );
}
我也试过禁用第三个窗格并将其添加到第一个选项卡搜索实现中,但由于第三个选项卡是在第一个选项卡之后定义的,所以出现了一个错误。
我也试过在一个函数中包含第三个tab的try catch,这样就可以在第一个tab的按钮点击时调用它。
请提出一个解决方案。任何人谁可以腾出一个想法,这一代码和援助的解决方案将高度赞赏。谢谢。
最佳答案
你看过黑莓主屏幕的onExposed
和onObscured
方法吗?
受保护的void onexposed()
当此屏幕被弹出的屏幕显示时调用
显示堆栈。screen的子类应该重写此方法
特别处理。
称赞回调已取消订阅()。
受保护的void onobscured()
当此屏幕被按下的新屏幕遮挡时调用
显示堆栈。screen的子类应该重写此方法
特殊处理。
称赞回调是onexposed()。