How to filter lookup values on a dialogfield in Report Dialog based on another dialogfield in AX 2012 AOT reports? - x++

How can i implement Customized lookup in Report Dialog box.
for example i have two fields in my report dialog 1) Custgroup 2) CustAccount
if i have selected a particuler cust group in first field then second field lookup should show only customers those come under this cust groups.
//class
public class ReportRun extends ObjectRun
{
DialogField dialogcustGroup,dialogcustaccount ;
CustTable obj_CustTable ;
}
//dialog method
public Object dialog(Object _dialog)
{
DialogRunbase dialog = _dialog;
DialogGroup toFromGroup;
Args _args;
str accountnum,custGroup;
;
// _args = new Args();
// obj_dev_CustTable = _args.record();
//accountnum = obj_dev_CustTable.AccountNum;
dialogcustGroup = dialog.addFieldValue(extendedTypeStr(CustGroup),CustGroup,"");
while select obj_CustTable
where obj_CustTable.AccountNum == dialogcustGroup .value()
{
CID = obj_dev_CustTable.CID;
dialogcustaccount =dialog.addFieldValue(ExtendedTypeStr(AccountNum),accountnum,"CID");
}
return dialog;
}
Any help would be great!!!!

The best way to do it is to override the lookup() method on the specified DialogField. See the example below - it works just fine.
class CustomizedLookup extends RunBase
{
DialogRunbase dialog;
DialogField dFieldCustGroup;
DialogField dFieldCustAccount;
CustGroupId fetchedCustGroup;
CustAccount fetchedAccountNum;
}
protected Object dialog()
{
dialog = super();
FieldCustGroup = dialog.addField(extendedTypeStr(CustGroupId),"sysLabel1");
dFieldCustGroup.allowEdit(true);
dFieldCustAccount = dialog.addField(extendedTypeStr(CustAccount),"sysLabel1");
dFieldCustAccount.allowEdit(false);
return dialog;
}
public void dialogPostRun(DialogRunbase _dialog)
{
super(_dialog);
// allow to call the event methods
// of this class (e.g. Fld1_1_modified() method)
_dialog.dialogForm().formRun().controlMethodOverload(true);
_dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}
private boolean Fld1_1_modified() // dFieldCustGroup
{
FormStringControl control;
boolean isFieldModified;
control = dialog.formRun().controlCallingMethod();
isFieldModified = control.modified();
if(isFieldModified)
{
fetchedCustGroup = dFieldCustGroup.value();
dFieldCustAccount.allowEdit(true);
}
return isFieldModified;
}
private void Fld2_1_lookup() //dFieldCustAccount
{
FormStringControl control = dialog.formRun().controlCallingMethod();
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(CustTable),control);
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
queryBuildDataSource = query.addDataSource(TableNum(CustTable));
queryBuildRange = queryBuildDataSource.addRange(FieldNum(CustTable, CustGroup));
queryBuildRange.value(fetchedCustGroup);
sysTableLookup.addLookupfield(fieldnum(CustTable, AccountNum));
sysTableLookup.addLookupfield(fieldnum(CustTable, CustGroup));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
public boolean getFromDialog()
{
boolean ret;
ret = super();
fetchedAccountNum = dFieldCustAccount.value();
return ret;
}
static void main(Args _e)
{
CustomizedLookup customizedLookup;
customizedLookup = new CustomizedLookup();
if (customizedLookup.prompt())
{
customizedLookup.run();
// do some actions with your data
customizedLookup.theAction();
}
}
private void theAction()
{
info(strFmt("Customer Group: %1",fetchedCustGroup));
info(strFmt("Account Number: %1",fetchedAccountNum));
}

Some more methods like pack , unpack and main method should be declared

public class CustAmountCalculation extends RunBase
{
DialogField fieldAccount;
CustAccount custAccount;
}
public Object dialog()
{
Dialog dialog;
DialogGroup groupCustomer;
dialog = super();
fieldAccount = dialog.addField(extendedTypeStr(custAccount), "CustomerAccount");
return dialog;
}
public boolean getFromDialog()
{
custAccount = fieldAccount.value();
return super();
}
public container pack()
{
return conNull();
}
public void run()
{
CustTable custTable;
CustTrans custTrans;
;
select sum(AmountMST) from custTrans where custTrans.AccountNum == custAccount;
info("You have enetered customer information");
info(strfmt("Account: %1", custAccount));
info(strFmt("Amount: %1", custTrans.AmountMST));
}
public boolean unpack(container _packedClass)
{
return true;
}
public static void main(Args _args)
{
CustAmountCalculation custAmountCalculation = new CustAmountCalculation();
if (CustAmountCalculation.prompt())
{
CustAmountCalculation.run();
}
}

Related

Filter ListView with SearchView xamarin

I want to filter Listview by Searchview
I use the following Adapter for the filter and it works if I haven't made any new additions to the adapter
When I add a new item to Listview, the search stops completely until I restart the program after adding, modifying or deleting it
full code
adapter class
Do you want to achieve the result like following GIF?
If you want to add the item to the listview, based on your adapter, you should item in the adapter like following code.
public class TableItemAdapter : BaseAdapter<TableItem>, IFilterable
{
public List<TableItem> _originalData;
public List<TableItem> _items;
private readonly Activity _context;
public TableItemAdapter(Activity activity, IEnumerable<TableItem> tableitems)
{
_items = tableitems.ToList();
_context = activity;
Filter = new TableItemFilter(this);
}
//Add data to the `_items`, listview will be updated, if add data in the activity,
//there are two different lists, so listview will not update.
public void AddData(TableItem tableItem)
{
_items.Add(tableItem);
NotifyDataSetChanged();
}
public override TableItem this[int position]
{
get { return _items[position]; }
}
public Filter Filter { get; private set; }
public override int Count
{
get { return _items.Count; }
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = _items[position];
View view = convertView;
if (view == null) // no view to re-use, create new
view = convertView ?? _context.LayoutInflater.Inflate(Resource.Layout.TableItem, null);
//view = _context.LayoutInflater.Inflate(Resource.Layout.TableItem, null);
view.FindViewById<TextView>(Resource.Id.Text1).Text = item.Heading;
view.FindViewById<TextView>(Resource.Id.Text2).Text = item.SubHeading;
return view;
}
public override void NotifyDataSetChanged()
{
// this.NotifyDataSetChanged();
base.NotifyDataSetChanged();
}
}
public class TableItemFilter :Filter
{
private readonly TableItemAdapter _adapter;
public TableItemFilter(TableItemAdapter adapter)
{
_adapter = adapter;
}
protected override FilterResults PerformFiltering(ICharSequence constraint)
{
var returnObj = new FilterResults();
var results = new List<TableItem>();
if (_adapter._originalData == null)
_adapter._originalData = _adapter._items;
if (constraint == null) return returnObj;
if (_adapter._originalData != null && _adapter._originalData.Any())
{
results.AddRange(
_adapter._originalData.Where(
item => item.SubHeading.ToLower().Contains(constraint.ToString()) | item.Heading.ToLower().Contains(constraint.ToString())));
}
returnObj.Values = FromArray(results.Select(r => r.ToJavaObject()).ToArray());
returnObj.Count = results.Count;
constraint.Dispose();
return returnObj;
}
protected override void PublishResults(ICharSequence constraint, FilterResults results)
{
using (var values = results.Values)
_adapter._items = values.ToArray<Java.Lang.Object>().Select(r => r.ToNetObject<TableItem>()).ToList();
_adapter.NotifyDataSetChanged();
// Don't do this and see GREF counts rising
constraint.Dispose();
results.Dispose();
}
}
public class JavaHolder : Java.Lang.Object
{
public readonly object Instance;
public JavaHolder(object instance)
{
Instance = instance;
}
}
public static class ObjectExtensions
{
public static TObject ToNetObject<TObject>(this Java.Lang.Object value)
{
if (value == null)
return default(TObject);
if (!(value is JavaHolder))
throw new InvalidOperationException("Unable to convert to .NET object. Only Java.Lang.Object created with .ToJavaObject() can be converted.");
TObject returnVal;
try { returnVal = (TObject)((JavaHolder)value).Instance; }
finally { value.Dispose(); }
return returnVal;
}
public static Java.Lang.Object ToJavaObject<TObject>(this TObject value)
{
if (Equals(value, default(TObject)) && !typeof(TObject).IsValueType)
return null;
var holder = new JavaHolder(value);
return holder;
}
}
}
Then in the activity, you add the data by adapter.
private void Button1_Click(object sender, System.EventArgs e)
{
tableItemAdapter.AddData(new TableItem() { Heading = "test1222", SubHeading = "sub Test" });
}
Here is my demo, you can download it.
https://github.com/851265601/Xamarin.Android_ListviewSelect/blob/master/XAListViewSearchDemo.zip

Updating adapter of AutoCompleteTextView from LiveData

I have a AutoCompleteTextView that I give it 2 different adapters depending on the amount of text that is being present at the textview - if it has 0 characters I want it to display a list of "recently searched" strings adapter, while if it has more than 1 characters I want it to display auto completion list.
My getRecentlySearchedQueries method along with the RecentSearchedViewModel-
private List<String> recentlySearchedQueries = new ArrayList<>(); // pasted from the top of the class
#Override
public void getRecentlySearchedQueries() {
recentSearchViewModel.getAllQueries().observe(getActivity(), databaseRecentlySearchList -> {
if (databaseRecentlySearchList == null) {
return;
}
for (int i = 0; i < databaseRecentlySearchList.size(); i++) {
Log.d("localDBValue", "Added value - " + databaseRecentlySearchList.get(i).toString() + "\n");
String query = databaseRecentlySearchList.get(i).getQuery();
recentlySearchedQueries.add(query);
}
//Log.d("localDBValue", "recent search list value - " + recentlySearchedQueries);
});
}
public class RecentSearchViewModel extends AndroidViewModel {
private RecentSearchRepository recentSearchRepository;
private LiveData<List<RecentSearchModel>> allRecentlySearched;
public RecentSearchViewModel(#NonNull Application application) {
super(application);
recentSearchRepository = new RecentSearchRepository(application);
allRecentlySearched = recentSearchRepository.getAllRecentSearches();
}
public void insert(RecentSearchModel model) {
recentSearchRepository.insert(model);
}
public void update(RecentSearchModel model) {
// add implementation in the future if needed
}
public void delete(RecentSearchModel model) {
// add implementation in the future if needed
}
public LiveData<List<RecentSearchModel>> getAllQueries() {
return allRecentlySearched;
}
}
public class RecentSearchRepository {
private RecentSearchDao recentSearchDao;
private LiveData<List<RecentSearchModel>> allRecentSearches;
public RecentSearchRepository(Application application) {
MarketplaceDatabase database = MarketplaceDatabase.getRecentSearchInstance(application);
recentSearchDao = database.recentSearchDao();
allRecentSearches = recentSearchDao.getRecentSearchList();
}
public void insert(RecentSearchModel model) {
new RecentSearchRepository.InsertRecentSearchAsyncTask(recentSearchDao).execute(model);
}
public void update (RecentSearchModel model) {
//TODO - implement in future if needed
}
public void delete(RecentSearchModel model) {
//TODO - implement in future if needed
}
public LiveData<List<RecentSearchModel>> getAllRecentSearches() {
return allRecentSearches;
}
private static class InsertRecentSearchAsyncTask extends AsyncTask<RecentSearchModel, Void, Void> {
private RecentSearchDao recentSearchDao;
public InsertRecentSearchAsyncTask(RecentSearchDao recentSearchDao) {
this.recentSearchDao = recentSearchDao;
}
#Override
protected Void doInBackground(RecentSearchModel... recentSearchModels) {
recentSearchDao.insert(recentSearchModels[0]);
return null;
}
}
private static class UpdateRecentSearchAsyncTask extends AsyncTask<RecentSearchModel, Void, Void> {
private RecentSearchDao recentSearchDao;
public UpdateRecentSearchAsyncTask(RecentSearchDao recentSearchDao) {
this.recentSearchDao = recentSearchDao;
}
#Override
protected Void doInBackground(RecentSearchModel... recentSearchModels) {
recentSearchDao.update(recentSearchModels[0]);
return null;
}
}
}
#Dao
public interface RecentSearchDao {
#Insert()
void insert(RecentSearchModel model);
#Update
void update(RecentSearchModel model);
#Delete
void delete(RecentSearchModel model);
#Query("select * from recent_search_table")
LiveData<List<RecentSearchModel>> getRecentSearchList();
}
#Entity(tableName = "recent_search_table")
public class RecentSearchModel {
#PrimaryKey(autoGenerate = true)
private int ID;
private String query;
public RecentSearchModel(){
}
public RecentSearchModel(String query) {
this.query = query;
}
public void setID(int ID) {
this.ID = ID;
}
public int getID() {
return ID;
}
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
#Override
public String toString() {
return "RecentSearchModel{" +
"query='" + query + '\'' +
'}';
}
#Override
public boolean equals(#Nullable Object obj) {
if (obj instanceof RecentSearchModel)
return this.query.equalsIgnoreCase(((RecentSearchModel) obj).query);
return false;
}
}
So, what I am doing here is for start getting all values inside my local DB and adding them to my String list that is part of the adapter. So far so good.
The issue I am facing is that the adapter won't show the amount of strings available in the list that populates it. In fact, it sometimes shows a view half-cut with wierd information, sometimes does not show anything and sometimes shows part of the corrent information. What am I missing?
Another thing I am facing is that the "recently searched" adapter won't work when clicking on the AutoCompleteTextView - it only works when typing and deleting values so the char length is 0. How can I make it work from start of focus?
Here is the way I am populating the information to the ViewModel -
/**
* Shows the searched products following
*/
#Override
public void getSearchedProducts(String searchedQuery) {
MarketplaceUtils.getSearchedProducts(searchedQuery, marketApiCalls, false, initialSearchTake, initialMarketplacePage, new MarketplaceUtils.OnProductsFetchCompleteListener() {
#Override
public void onSuccess(List<MiniProductModel> list) {
if (!searchedQuery.equals(currentSearchedText))
return;
if (list == null) {
//reaching here means we do not have a result to show to the UI so we empty the list.
currentProductList.clear();
productsAdapter.notifyDataSetChanged();
return;
}
if (searchedQuery.length() > 3 && searchAutoCompleteStrings.contains(searchedQuery)) {
Log.d("localDBValue", "searchedValue - " + searchedQuery);
recentSearchViewModel.insert(new RecentSearchModel(searchedQuery));
}
mPresenter.setDiscoverProductsLayoutVisibility(View.GONE);
currentProductList.clear();
currentProductList.addAll(list);
productsAdapter.notifyDataSetChanged();
}
#Override
public void onError(Throwable throwable) {
Log.d("searchedProducts", throwable.getMessage());
}
});
}
The default behaviour for #Insert method of Room is OnConflictStrategy.ABORT - so what I did is to implement equals() method to verify that the RecentSearchModels that are being compared are compared by their string value. Still does seems to effect anything.

button inside column for each row in tableview

In my TableView I have column with button for each row for update so I need when click the button to take all the values from the row to a new fxml window
This is my contractor class:
public class constractor {
private String co_id;
private String co_name;
private String co_address;
private String co_create_date;
private String co_description;
private String co_mobile;
private String co_type_compile;
private String co_status;
private String co_type_model;
private Button button;
public constractor(String co_id, String co_name, String co_type_compile, String co_description, String co_create_date, String co_status, String co_address, String co_mobile, String co_type_model, String button) {
this.co_id = co_id;
this.co_name = co_name;
this.co_type_compile = co_type_compile;
this.co_description = co_description;
this.co_create_date = co_create_date;
this.co_status = co_status;
this.co_address = co_address;
this.co_mobile = co_mobile;
this.co_type_model = co_type_model;
this.button = new Button("edit");
}
public String getCo_id() {
return co_id;
}
public void setCo_id(String co_id) {
this.co_id = co_id;
}
public String getCo_name() {
return co_name;
}
public void setCo_name(String co_name) {
this.co_name = co_name;
}
public String getCo_address() {
return co_address;
}
public void setCo_address(String co_address) {
this.co_address = co_address;
}
public String getCo_create_date() {
return co_create_date;
}
public void setCo_create_date(String co_create_date) {
this.co_create_date = co_create_date;
}
public String getCo_description() {
return co_description;
}
public void setCo_description(String co_description) {
this.co_description = co_description;
}
public String getCo_mobile() {
return co_mobile;
}
public void setCo_mobile(String co_mobile) {
this.co_mobile = co_mobile;
}
public String getCo_type_compile() {
return co_type_compile;
}
public void setCo_type_compile(String co_type_compile) {
this.co_type_compile = co_type_compile;
}
public String getCo_status() {
return co_status;
}
public void setCo_status(String co_status) {
this.co_status = co_status;
}
public String getCo_type_model() {
return co_type_model;
}
public void setCo_type_model(String co_type_model) {
this.co_type_model = co_type_model;
}
public Button getButton() {
return button;
}
public void setButton(Button button) {
this.button = button;
}
}
This is my class for table:
public class MainscreenController implements Initializable {
#FXML
private TableView<constractor> co_tableview;
#FXML
private TableColumn<constractor, String> col_id;
#FXML
private TableColumn<constractor, String> col_name;
#FXML
private TableColumn<constractor, String> col_compaile_type;
#FXML
private TableColumn<constractor, String> col_description;
#FXML
private TableColumn<constractor, String> col_ceartedat;
#FXML
public TableColumn<constractor, String> col_status;
#FXML
private TableColumn<constractor, String> col_mobile;
#FXML
private TableColumn<constractor, String> col_type_model;
#FXML
private TextField search;
#FXML
private TableColumn<constractor, Button> col_button;
int indexorder = -1;
ObservableList<constractor> orderdata = FXCollections.observableArrayList();
#FXML
public void ordertables() {
Connection con = DB.getConnection();
orderdata.clear();
try {
try (ResultSet rs = con.createStatement().executeQuery("select * from mr_order")) {
while (rs.next()) {
orderdata.add(new constractor(
rs.getString("co_id"),
rs.getString("co_name"),
rs.getString("co_type_model"),
rs.getString("co_description"),
rs.getString("co_create_date"),
rs.getString("co_status"),
rs.getString("co_mobile"),
rs.getString("co_address"),
rs.getString("co_type_compile"),
rs.getString("co_user_id")
));
}
countneworder();
}
} catch (SQLException ex) {
Logger.getLogger(MainscreenController.class.getName()).log(Level.SEVERE, null, ex);
}
}
public int tablesandsearchorder() {
////tableview Itemsinserting
col_id.setCellValueFactory(new PropertyValueFactory<>("co_id"));
col_name.setCellValueFactory(new PropertyValueFactory<>("co_name"));
col_compaile_type.setCellValueFactory(new PropertyValueFactory<>
("co_type_compile"));
col_description.setCellValueFactory(new PropertyValueFactory<>
("co_description"));
col_ceartedat.setCellValueFactory(new PropertyValueFactory<>
("co_create_date"));
col_status.setCellValueFactory(new PropertyValueFactory<>("co_status"));
col_mobile.setCellValueFactory(new PropertyValueFactory<>("co_mobile"));
col_type_model.setCellValueFactory(new PropertyValueFactory<>
("co_type_model"));
col_button.setCellValueFactory(new PropertyValueFactory<>("button"));
co_tableview.setItems(orderdata);
co_tableview.getItems().setAll(orderdata);
co_tableview.itemsProperty().addListener((observable, oldItems, newItems)
-> {
countorder.textProperty().bind(
Bindings.size(newItems).asString());
});
// 2. Set the filter Predicate whenever the filter changes.
search.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
filteredData.setPredicate(constractor -> {
// If filter text is empty, display all persons.
if (newValue == null || newValue.isEmpty()) {
return true;
}
// Compare first name and last name of every person with filter text.
String lowerCaseFilter = newValue.toLowerCase();
if
(constractor.getCo_name().toLowerCase().contains(lowerCaseFilter)) {
return true; // Filter matches first name.
} else if (constractor.getCo_id().toLowerCase().contains(lowerCaseFilter)) {
return true; // Filter matches last name.
} else if
(constractor.getCo_description().toLowerCase().contains(lowerCaseFilter)) {
return true; // Filter matches last name.
}
return false; // Does not match.
});
});
// 3. Wrap the FilteredList in a SortedList.
SortedList<constractor> sortedData = new SortedList<>(filteredData);
// 4. Bind the SortedList comparator to the TableView comparator.
sortedData.comparatorProperty().bind(co_tableview.comparatorProperty());
// 5. Add sorted (and filtered) data to the table.
co_tableview.setItems(sortedData);
return 0;
}
#FXML
public void openinsert() {
try {
//in this fxml i create the new order and also i need for update the status the order from this fxml when i click the button inside the tableview
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("createorder.fxml"));
Scene scene = new Scene(fxmlLoader.load());
Stage stage = new Stage();
stage.setTitle("neworder");
stage.setScene(scene);
stage.setFullScreen(false);
stage.setResizable(false);
stage.setMinHeight(400);
stage.setMinWidth(600);
stage.show();
} catch (IOException e) {
Logger logger = Logger.getLogger(getClass().getName());
logger.log(Level.SEVERE, "Failed to create new Window.", e);
}
}
It's usually recommended not mixing the view code (Button) with the model code (constractor). Instead you should use a custom TableCell class for the column.
Assuming you know how to pass the data (otherwise take a look here: Passing Parameters JavaFX FXML), all required info should be available via the constractor instance which you should pass to the new scene.
MainscreenController
#FXML
private TableColumn<constractor, Void> col_button;
...
private void editConstractor(constractor constractor) {
// TODO: implement
}
#FXML
private void initialize() {
col_button.setCellFactory(col -> new TableCell<constractor, Void>() {
private final Button button;
{
button = new Button("edit");
button.setOnAction(evt -> {
constractor item = getTableRow().getItem();
editConstractor(item);
});
}
#Override
protected void updateItem(Void item, boolean empty) {
super.updateItem(item, empty);
setGraphic(empty ? null : button);
}
});
}
You also need to remove the cellValueFactory for the button column.
Note:
Sticking to the java naming conventions would make the code easier to read. (Type names should start with an uppercase letter and identifiers should use camelCase instead of underscores assuming they're not for a static final field.)
constractor is most likely misspelled. Did you mean contractor? I recommend using the renaming functionality of your IDE to fix this typo...
(In my code I used the same spelling for the editConstractor method.)

How add properties to the Vaadin Calendar BasicEvent?

I am implementing the Vaadin 7 Calendar and require to display more
event information than is contained in BasicEvent.
Below is some of the code I am using (events are not being displayed
on calendar):
please can you inform me what I need to add/change?
Thank you Steve...
public class CalEvent extends BasicEvent {
private java.lang.String customer = "";
public CalEvent() {
}
public java.lang.String getCustomer() {
return customer;
}
public void setCustomer(java.lang.String customer) {
this.customer = customer;
}
}
public class EvtProvider extends BasicEventProvider {
public void addEvent(CalEvent event) {
super.addEvent(event);
}
public void removeEvent(Event event) {
super.removeEvent(event);
}
}
public class Mgr {
Mgr() {
cal = new Calendar("My Calendar");
EvtProvider evtProvider = new EvtProvider();
cal.setEventProvider(evtProvider);
List<CalEvent> lst = getCalEvents();
for (CalEvent ev : lst) {
cal.addEvent(ev);
}
}
"more event information than is contained in BasicEvent."
For example?
BasicEvent can display a lot of content in event or Event description.
http://i.stack.imgur.com/uRlN4.png

Keywordfilter field in blackberry

I used a keywordfilter for a list which is populated from db .Its working good .Imagine the list contains a phrase 'A big bat' and there are other words starting with 'b' like books etc .But when I give 'b' in the search field the phrase 'A big bat' appears first and then only words starting with 'b'.Please help me to fix it
please see my code
public final class KeywordFilter
{
private KeywordFilterField _keywordFilterField;
private WordList _wordList;
private Vector _words;
public KeywordFilter()
{
_words = getDataFromDatabase();
if(_words != null)
{
_wordList = new WordList(_words);
_keywordFilterField = new KeywordFilterField();
_keywordFilterField.setSourceList(_wordList, _wordList);
CustomKeywordField customSearchField = new CustomKeywordField();
_keywordFilterField.setKeywordField(customSearchField);
KeywordFilterScreen screen = new KeywordFilterScreen(this);
screen.setTitle(_keywordFilterField.getKeywordField());
screen.add(_keywordFilterField);
UiApplication ui = UiApplication.getUiApplication();
ui.pushScreen(screen);
}
else
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("Error reading data file.");
System.exit(0);
}
});
}
}
KeywordFilterField getKeywordFilterField()
{
return _keywordFilterField;
}
private Vector getDataFromDatabase()
{
Vector words = new Vector();
Database d;
for(;;)
{
try
{
URI myURI=URI.create("file:///SDCard/Databases/MyTestDatabase.db");
d=DatabaseFactory.open(myURI);
Statement st=d.createStatement("select (select distinct group_concat(eng) fromEnglish),group_concat(mal) from English e ,Malayalam m where e.Ecode=m.Mcode group by eng");
st.prepare();
net.rim.device.api.database.Cursor c=st.getCursor();
Row r;
while(c.next())
{
r=c.getRow();
String w=r.getString(0);
String meaning=r.getString(1);
words.addElement(new Word(w,meaning));
}
st.close();
d.close();
}
catch ( Exception e )
{
System.out.println( e.getMessage() );
e.printStackTrace();
}
return words;
}
}
void addElementToList(Word w)
{
_wordList.addElement(w);
_keywordFilterField.updateList();
}
final static class CustomKeywordField extends BasicEditField
{
CustomKeywordField()
{
super(USE_ALL_WIDTH|NON_FOCUSABLE|NO_LEARNING|NO_NEWLINE);
setLabel("Search: ");
}
protected boolean keyChar(char ch, int status, int time)
{
switch(ch)
{
case Characters.ESCAPE:
if(super.getTextLength() > 0)
{
setText("");
return true;
}
}
return super.keyChar(ch, status, time);
}
protected void paint(Graphics graphics)
{
super.paint(graphics);
getFocusRect(new XYRect());
drawFocus(graphics, true);
}
}
}
class KeywordFilterScreen extends MainScreen
{
private KeywordFilter _app;
private KeywordFilterField _keywordFilterField;
public KeywordFilterScreen(KeywordFilter app)
{
_app = app;
_keywordFilterField = _app.getKeywordFilterField();
}
protected boolean keyChar(char key, int status, int time)
{
if (key == Characters.ENTER)
{
displayInfoScreen();
// Word w = (Word)_keywordFilterField.getSelectedElement();
// Status.show(w.getMeaning());
return true;
}
return super.keyChar(key, status, time);
}
public boolean invokeAction(int action)
{
switch(action)
{
case ACTION_INVOKE:
displayInfoScreen();
return true;
}
return super.invokeAction(action);
}
private void displayInfoScreen()
{
Word w = (Word)_keywordFilterField.getSelectedElement();
if(w != null)
{
InfoScreen infoScreen = new InfoScreen(w);
UiApplication ui=UiApplication.getUiApplication();
ui.pushScreen(infoScreen);
}
}
public boolean onSavePrompt()
{
return true;
}
private final static class InfoScreen extends MainScreen
{
InfoScreen(Word w)
{
setTitle(w.toString());
BasicEditField popField = new BasicEditField(" ",w.getMeaning(),300,Field.NON_FOCUSABLE);
FontManager.getInstance().load("DC124.TTF", "MyFont", FontManager.APPLICATION_FONT) ;
{
try {
FontFamily typeface = FontFamily.forName("MyFont");
Font myFont = typeface.getFont(Font.PLAIN, 25);
popField.setFont(myFont);
add(popField);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();}
}
}
}
}
This query is useful for you:
SELECT Name FROM Employee where Name like '%d%' order by Name;
Here Name is my column-name;
Try this;
I think you are using query like following
select colomname from tablename where colomname GLOB '%b%';
here you get all names which are contain letter 'b' (case sensitive)
if you want all words which are strted with letter 'b' use should writr query like
select colomname from tablename where colomname GLOB 'b%' order by colomname ;
here i am using "GLOB" it gives case sensitive to the out put records if you dont need case sensitive then you can use "LIKE" key word
thanks

Resources