I am developing a BlackBerry project under JDE 4.6.1. The problem is that when adding an item to the list, a NullPointerException is thrown from method measureListRow
NPE callstack:
CustomerListField(ObjectListField).measureListRow(ListField, int, int)
CustomerListField(ListField).layout(int, int)
CustomerListField(ObjectListField).layout(int, int)
VList(Manager).layoutChild(Field, int, int)
Notes:
db_.getDataAccess() - database
getListCount - getting the number of items in the list
CustomerListItem - the structure of a list item
And the relevant code:
public class CustomerListField extends ObjectListField implements ListFieldCallback, ChangeListener {
private PagedDataFetcher dataFetcher = new CustomerListPagedDataFetcher();
…
public CustomerListField() {
try {
super.set(new Object[db_.getDataAccess().getListCount()]);
} catch (Throwable e) {
}
}
public void drawListRow(ListField listField, Graphics g, int index, int y,
int width) {
CustomerListItem currentRow = (CustomerListItem) get(listField, index);
…
}
public Object get(ListField list, int index) {
try {
return dataFetcher.getRowAtIndex(index);
} catch (Throwable e) {
return null;
}
}
// To obtain the data
public class CustomerListPagedDataFetcher extends PagedDataFetcher {
protected Vector get(int from, int to) throws Exception {
return DataAccess.getDataAccess().getLists(from, to);
}
}
/**
* layout for list
*/
final class VList extends VerticalFieldManager {
private final ObjectListField list;
int maxHeight = Display.getHeight() - getFont().getHeight() * 2 - 5;
VList(ObjectListField list) {
super(Manager.VERTICAL_SCROLLBAR | Manager.VERTICAL_SCROLL);
this.list = list;
}
public int getPreferredHeight() {
return 45 * list.getSize();
}
protected void sublayout(int width, int height) {
super.sublayout(width, height);
setExtent(width, maxHeight);
}
}
If you're getting a NullPointerException in measureRowList, the first place I'd look is the source of that method to see what null value is being dereferenced. It looks like you didn't include the source for that method though.
Related
I have an application with several Forms. Two of them are quite similar, they have features in the form of VCL objects (labels, images, etc...) in common, which I named the same.
I want to have a function in a specific class which can accept one of these two Form as a parameter in order to modify the parameters that they have in common. The solution I came around does not seem to work.
As my application is quite big and complicated, I replicated the problem using a small example.
First, below is an example of my MainForm :
And an example of one subForm (they are all arranged in a similar way)
I have an additionnal class which is used to fill in the Edits on the subForms. The code for this class is the following:
#pragma hdrstop
#include "master_class.h"
#include "sub_Form2.h"
#include "sub_Form3.h"
#include "sub_Form4.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
Master::Master(void)
{
}
Master::~Master(void)
{
}
void Master::WriteToForm(TForm* Form)
{
TForm2* curForm = static_cast<TForm2*>(Form);
TForm3* self = dynamic_cast<TForm3*>(Form);
TForm2* self2 = dynamic_cast<TForm2*>(Form);
if (self != NULL && self2 == NULL) {
TForm3* curForm = static_cast<TForm3*>(Form);
}
else if (self == NULL && self2 != NULL) {
TForm2* curForm = static_cast<TForm2*>(Form);
}
curForm -> Edit1 -> Text = "blablabla_1";
curForm -> Edit2 -> Text = "blablabla_2";
}
And in the MainForm, the code for the "Fill Form2" button is the following:
Master1 -> WriteToForm(Form2);
where Master1 is just an object of the Master class.
This works very well for Form2 :
But for Form3, which is filled up using Master1 -> WriteToForm(Form3), here is what I get, which the same pb than in my real application:
So what should go to the Edit, is misplaced. I think the main pb comes from the fact that I did not create every label, edit, etc... on the same order. I did that on purpose to mimic my real application. To verify this, I created a 3rd subForm, where this time the VCL objects were created in the same order as my first subForm, and this works:
So I would suspect that this comes from the initial cast
TForm2* curForm = static_cast<TForm2*>(Form);
When I pass Form3 as an argument, Form3 is somewhat casted into the "shape" of Form2, which is not defined in the same order. Maybe this could be corrected by modifying directly the DFM file, but it is not a realistic approach for my main app.
I do this initial cast otherwise I get a compilation error saying that curForm is not known at the first line
curForm -> Edit1 -> Text = "blablabla_1";
So, is there a better way to pass the Form as an argument to the WriteToForm function?
Just because two types are similar does not mean they are related. Your code does not work because your two Form classes are not related to each other in any way. You can't just cast one to the other arbitrarily.
To solve this, you have several options:
code for both Form classes separately, eg:
void Master::WriteToForm(TForm* Form)
{
TForm2* curForm2 = dynamic_cast<TForm2*>(Form);
TForm3* curForm3 = dynamic_cast<TForm3*>(Form);
if (curForm2)
{
curForm2->Edit1->Text = _D("blablabla_1");
curForm2->Edit2->Text = _D("blablabla_2");
}
else if (curForm3)
{
curForm3->Edit1->Text = _D("blablabla_1");
curForm3->Edit2->Text = _D("blablabla_2");
}
}
Or:
void WriteToForm(TForm2* Form);
void WriteToForm(TForm3* Form);
...
void Master::WriteToForm(TForm2* Form)
{
Form->Edit1->Text = _D("blablabla_1");
Form->Edit2->Text = _D("blablabla_2");
}
void Master::WriteToForm(TForm3* Form)
{
Form->Edit1->Text = _D("blablabla_1");
Form->Edit2->Text = _D("blablabla_2");
}
Make your function use a template (however, be aware of this: Why can templates only be implemented in the header file?):
template<typename T>
void WriteToForm(T* Form);
...
void Master::WriteToForm<T>(T* Form)
{
Form->Edit1->Text = _D("blablabla_1");
Form->Edit2->Text = _D("blablabla_2");
}
make the two Form classes derive from a common base class or interface, eg:
class TBaseForm : public TForm
{
public:
inline __fastcall TBaseForm(TComponent *Owner) : TForm(Owner) {}
virtual void SetEdit1(const String &Text) = 0;
virtual void SetEdit2(const String &Text) = 0;
};
...
class TForm2 : public TBaseForm
{
...
public:
__fastcall TForm2(TComponent *Owner);
...
void SetEdit1(const String &NewText);
void SetEdit2(const String &NewText);
};
__fastcall TForm2::TForm2(TComponent *Owner)
: TBaseForm(Owner)
{
...
}
void TForm2::SetEdit1(const String &NewText)
{
Edit1->Text = NewText;
}
void TForm2::SetEdit2(const String &NewText)
{
Edit2->Text = NewText;
}
...
repeat for TForm3...
...
void Master::WriteToForm(TBaseForm* Form)
{
Form->SetEdit1(_D("blablabla_1"));
Form->SetEdit2(_D("blablabla_2"));
}
Or:
__interface INTERFACE_UUID("{E900785E-0151-480F-A33A-1F1452A431D2}")
IMyIntf : public IInterface
{
public:
virtual void SetEdit1(const String &Text) = 0;
virtual void SetEdit2(const String &Text) = 0;
};
...
class TForm2 : public TForm, public IMyIntf
{
...
public:
__fastcall TForm2(TComponent *Owner);
...
void SetEdit1(const String &NewText);
void SetEdit2(const String &NewText);
};
__fastcall TForm2::TForm2(TComponent *Owner)
: TForm(Owner)
{
...
}
void TForm2::SetEdit1(const String &NewText)
{
Edit1->Text = NewText;
}
void TForm2::SetEdit2(const String &NewText)
{
Edit2->Text = NewText;
}
...
repeat for TForm3...
...
void Master::WriteToForm(IMyIntf* Intf)
{
Intf->SetEdit1(_D("blablabla_1"));
Intf->SetEdit2(_D("blablabla_2"));
}
use RTTI to access the fields, eg:
#include <System.Rtti.hpp>
void Master::WriteToForm(TForm* Form)
{
TRttiContext Ctx;
TRttiType *FormType = Ctx.GetType(Form->ClassType());
TRttiField *Field = FormType->GetField(_D("Edit1"));
if (Field)
{
TValue value = Field->GetValue(Form);
if( (!value.Empty) && (value.IsObject()) )
{
TObject *Obj = value.AsObject();
// Either:
static_cast<TEdit*>(Obj)->Text = _D("blablabla_1");
// Or:
TRttiProperty *Prop = Ctx.GetType(Obj->ClassType())->GetProperty(_D("Text"));
if (Prop) Prop->SetValue(Obj, String(_D("blablabla_1")));
}
}
Field = FormType->GetField(_D("Edit2"));
if (Field)
{
TValue value = Field->GetValue(Form);
if( (!value.Empty) && (value.IsObject()) )
{
TObject *Obj = value.AsObject();
// Either:
static_cast<TEdit*>(Obj)->Text = _D("blablabla_2");
// Or:
TRttiProperty *Prop = Ctx.GetType(Obj->ClassType())->GetProperty(_D("Text"));
if (Prop) Prop->SetValue(Obj, String(_D("blablabla_2")));
}
}
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I am able to establish communication between my microcontroller system and computer through serial port and TCP/IP, and able to send/ receive data.
I want to develop a graphical front-end application on my PC in which i can view some values/plot some graphs based on the data sent by my microcontroller.
I have some exposure to Visual Studio and MATLAB, and know C/C++ languages.
Which development environment should i use for the front-end development ??
Any tutorials/books/links regarding the same ??
This is actually an appendix to a comment, where I bragged about a small wrapper for charts, for creating XYPlots.
create a winform, rename it to XYPlot.
add a chart, and name it plotChart
add this as code..
now you can plot easily from your code ..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace Plot
{
public partial class XYPlot : Form
{
#region constructors
public string Title
{
get
{
return this.Text;
}
set
{
this.Text = "XYPlot : " + value;
}
}
//default, used for multiplots
public XYPlot()
{
InitializeComponent();
InitializeChartStyles();
}
private void InitializeChartStyles()
{
plotChart.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
plotChart.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
plotChart.ChartAreas["ChartArea1"].AxisX.MinorGrid.Enabled = false;
plotChart.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;
plotChart.ChartAreas["ChartArea1"].AxisY.MinorGrid.Enabled = false;
}
//one-offs, used for simple plots of data
public XYPlot(string name, Series series)
{
InitializeComponent();
InitializeChartStyles();
this.Add(series);
this.Show();
}
public XYPlot(string name, DataPointCollection XYpoints)
{
InitializeComponent();
InitializeChartStyles();
this.Add(name, XYpoints);
this.Show();
}
public XYPlot(string name, List<Tuple<double, double>> XYpoints)
{
InitializeComponent();
InitializeChartStyles();
this.Add(name, XYpoints);
this.Show();
}
public XYPlot(string name, List<double> X, List<double> Y)
{
InitializeComponent();
InitializeChartStyles();
this.Add(name, X, Y);
this.Show();
}
public XYPlot(string name, List<double> Y, double xIncrements = 1.0, double xOffset = 0.0)
{
InitializeComponent();
InitializeChartStyles();
this.Add(name, Y, xIncrements);
this.Show();
}
private void FormPlot_Load(object sender, EventArgs e)
{
Clear();
}
#endregion
#region getNextDefault
private List<Color> usedColors = new List<Color>();
private Color getNextDefaultColor()
{
switch(usedColors.Count)
{
case 1:
return Color.Red;
case 2:
return Color.Green;
case 3:
return Color.Black;
default:
return Color.Blue;
}
}
private Series newDefaultSeries(string Name)
{
var series = new System.Windows.Forms.DataVisualization.Charting.Series
{
Name = Name,
BorderWidth = 2,
Color = getNextDefaultColor(),
IsVisibleInLegend = true,
IsXValueIndexed = false,
ChartType = SeriesChartType.Line
};
usedColors.Add(series.Color);
return series;
}
#endregion
#region public methods
public void Clear()
{
plotChart.Series.Clear();
usedColors.Clear();
}
public Series getSeries(string Name)
{
return plotChart.Series[Name];
}
#region Add
public void Add(string Name, DataPointCollection XYpoints)
{
Series series = newDefaultSeries(Name);
plotChart.Series.Add(series);
//shallow copy
foreach (DataPoint p in XYpoints)
{
series.Points.Add(p);
}
//invalidates the old surfcace, and thus requests a redraw
plotChart.Refresh();
}
public void Add(string Name, List<Tuple<double, double>> XYpoints)
{
Series series = newDefaultSeries(Name);
plotChart.Series.Add(series);
//shallow copy
foreach (Tuple<double, double> XY in XYpoints)
{
series.Points.AddXY(XY.Item1, XY.Item2);
}
//invalidates the old surfcace, and thus requests a redraw
plotChart.Refresh();
}
public void Add(string Name, List<double> X, List<double> Y)
{
Series series = newDefaultSeries(Name);
plotChart.Series.Add(series);
if (X.Count != Y.Count)
throw new Exception("X and Y vectors must be of same length, otherwise I cannot plot them in an XY plot!");
//shallow copy
for (int i = 0; i < X.Count; i++)
{
series.Points.AddXY(X[i], Y[i]);
}
//invalidates the old surfcace, and thus requests a redraw
plotChart.Refresh();
}
public void Add(string Name, List<double> Y, double xIncrements = 1.0, double xOffset = 0.0)
{
Series series = newDefaultSeries(Name);
plotChart.Series.Add(series);
//shallow copy
if (Y != null)
{
for (int i = 0; i < Y.Count; i++)
{
double x = ((double)i) * xIncrements + xOffset;
series.Points.AddXY(x, Y[i]);
}
}
//invalidates the old surface, and thus requests a redraw
plotChart.Refresh();
}
public void Add(System.Windows.Forms.DataVisualization.Charting.Series series)
{
plotChart.Series.Add(series);
plotChart.Refresh();
}
#endregion
#region updateSeries
public void updateSeries(string Name, DataPointCollection XYpoints)
{
try
{
if (plotChart.Series[Name] == null)
Add(Name, XYpoints);
}
catch
{
Add(Name, XYpoints);
}
//shallow copy
foreach (DataPoint p in XYpoints)
{
plotChart.Series[Name].Points.Add(p);
}
//invalidates the old surfcace, and thus requests a redraw
plotChart.Refresh();
}
public void updateSeries(string Name, List<Tuple<double, double>> XYpoints)
{
try
{
if (plotChart.Series[Name] == null)
Add(Name, XYpoints);
}
catch
{
Add(Name, XYpoints);
}
//shallow copy
foreach (Tuple<double, double> XY in XYpoints)
{
plotChart.Series[Name].Points.AddXY(XY.Item1, XY.Item2);
}
//invalidates the old surfcace, and thus requests a redraw
plotChart.Refresh();
}
public void updateSeries(string Name, List<double> X, List<double> Y)
{
try
{
if (plotChart.Series[Name] == null)
Add(Name, X, Y);
}
catch
{
Add(Name, X, Y);
}
plotChart.Series[Name].Points.Clear();
if (X.Count != Y.Count)
throw new Exception("X and Y vectors must be of same length, otherwise I cannot plot them in an XY plot!");
//shallow copy
for (int i = 0; i < X.Count; i++)
{
plotChart.Series[Name].Points.AddXY(X[i], Y[i]);
}
//invalidates the old surface, and thus requests a redraw
plotChart.Refresh();
}
public void updateSeries(string Name, List<double> Y, double xIncrements = 1.0, double xOffset = 0.0)
{
try
{
if (plotChart.Series[Name] == null)
Add(Name, Y, xIncrements, xOffset);
}
catch
{
Add(Name, Y, xIncrements, xOffset);
}
plotChart.Series[Name].Points.Clear();
//shallow copy
if (Y != null)
{
for (int i = 0; i < Y.Count; i++)
{
double x = ((double)i) * xIncrements + xOffset;
plotChart.Series[Name].Points.AddXY(x, Y[i]);
}
}
//invalidates the old surface, and thus requests a redraw
plotChart.Refresh();
}
public void updateSeries(System.Windows.Forms.DataVisualization.Charting.Series series)
{
try
{
if (plotChart.Series[series.Name] == null)
Add(series);
}
catch
{
Add(series);
}
plotChart.Series[series.Name] = series;
plotChart.Refresh();
}
#endregion
#endregion
}
}
As suggested by Joe, i decided to go ahead with Qt.
The following links are useful for installing and getting started with Qt on windows.
Installation:-
https://zahidhasan.wordpress.com/2014/04/29/how-to-install-qt-4-8-mingw-and-qt-creator-on-windows-8-1/
Reference:-
http://www-cs.ccny.cuny.edu/~wolberg/cs221/qt/books/C++-GUI-Programming-with-Qt-4-1st-ed.pdf
Regards,
Abhishek.
After lots of research on implementing IntentServices and Alarms together, I've come up with this. I don't know exactly what happens with this code so I need help in knowing exactly what is going on.
public class MainActivity{
//....
public void onNewItemAdded(String[] _entry){
//...
Intent intent = new Intent(MainActivity.this, UpdateService.class);
startService(intent);
}
//....
}
public class AlarmReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent startIntent = new Intent(context, UpdateService.class);
context.startService(startIntent);
}
public static final String ACTION_REFRESH_ALARM = "com.a.b.ACTION_REFRESH_ALARM";
}
public class UpdateService extends IntentService{
//...
#Override
public void onCreate() {
super.onCreate();
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
String ALARM_ACTION = AlarmReceiver.ACTION_REFRESH_ALARM;
Intent intentToFire = new Intent(ALARM_ACTION);
alarmIntent = PendingIntent.getBroadcast(this, 0, intentToFire, 0);
}
#Override
protected void onHandleIntent(Intent intent) {
Context context = getApplicationContext();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
int updateFreq = Integer.parseInt(prefs.getString(
PreferencesActivity.PREF_UPDATE_FREQ, "60"));
boolean autoUpdateChecked = prefs.getBoolean(
PreferencesActivity.PREF_AUTO_UPDATE, false);
if (autoUpdateChecked) {
int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP;
long timeToRefresh = SystemClock.elapsedRealtime() + updateFreq
* 60 * 1000;
alarmManager.setInexactRepeating(alarmType, timeToRefresh,
updateFreq * 60 * 1000, alarmIntent);
}
else {
alarmManager.cancel(alarmIntent);
}
refreshKeywords();
}
}
My aim is to get the refreshKeywords() method to be called every minute. Also, what happens if the onNewItemAdded() method is called more than once?
Sorry if this question is stupid, I'm a beginner.
If you wish you to call refreshKeywords()method to be called every minutes why do you use AlarmManager like this,
private void ServiceRunningBackground() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
final int restartAlarmInterval = 6000;
final int resetAlarmTimer = 2*1000;
final Intent restartIntent = new Intent(this, MyService.class);
restartIntent.putExtra("ALARM_RESTART_SERVICE_DIED", true);
final AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Handler restartServiceHandler = new Handler()
{
#Override
public void handleMessage(Message msg) {
PendingIntent pintent = PendingIntent.getService(getApplicationContext(), 0, restartIntent, 0);
alarmMgr.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + restartAlarmInterval, pintent);
sendEmptyMessageDelayed(0, resetAlarmTimer);
}
};
restartServiceHandler.sendEmptyMessageDelayed(0, 0);
}
}
Just call this method where ever you want and set the time accordingly
Does exist any method which bind BooleanProperty to conjunction of every element in ObservableList?
ObservableList<BooleanProperty> list;
list = FXCollections.observableList(new ArrayList<BooleanProperty>));
BooleanProperty emptyProperty = new SimpleBooleanProperty();
emptyProperty.bind(Bindings.conunction(list));`
Is there such a method as:
static BooleanBinding conjunction(ObservableList<BooleanProperty> op)
There is no conjunction api defined in the JavaFX 2.2 platform.
You could create a ConjunctionBooleanBinding (aka AllTrueBinding) by subclassing BooleanBinding.
Accept the ObservableList in the constructor of your new class, and use the low level binding api in an overridden computeValue method to set the binding value based upon logically anding together all of the boolean values in the list.
Here is a sample implementation. The sample could be further performance optimized and make use of WeakReferences, so it does not require manual disposition.
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.BooleanProperty;
import javafx.collections.*;
public class AllTrueBinding extends BooleanBinding {
private final ObservableList<BooleanProperty> boundList;
private final ListChangeListener<BooleanProperty> BOUND_LIST_CHANGE_LISTENER =
new ListChangeListener<BooleanProperty>() {
#Override public void onChanged(
ListChangeListener.Change<? extends BooleanProperty> change
) {
refreshBinding();
}
};
private BooleanProperty[] observedProperties = {};
AllTrueBinding(ObservableList<BooleanProperty> booleanList) {
booleanList.addListener(BOUND_LIST_CHANGE_LISTENER);
boundList = booleanList;
refreshBinding();
}
#Override protected boolean computeValue() {
for (BooleanProperty bp: observedProperties) {
if (!bp.get()) {
return false;
}
}
return true;
}
#Override public void dispose() {
boundList.removeListener(BOUND_LIST_CHANGE_LISTENER);
super.dispose();
}
private void refreshBinding() {
super.unbind(observedProperties);
observedProperties = boundList.toArray(new BooleanProperty[0]);
super.bind(observedProperties);
this.invalidate();
}
}
And here is a test harness to demonstrate how it works:
import java.util.*;
import javafx.beans.property.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class ListBindingTest {
final BooleanProperty a = new SimpleBooleanProperty(true);
final BooleanProperty b = new SimpleBooleanProperty(true);
final BooleanProperty c = new SimpleBooleanProperty(true);
final BooleanProperty d = new SimpleBooleanProperty(true);
final ObservableList<BooleanProperty> booleanList =
FXCollections.observableArrayList(a, b, c, d);
public static void main(String[] args) {
new ListBindingTest().test();
}
private void test() {
AllTrueBinding at = new AllTrueBinding(booleanList);
System.out.println(at.get() + forArrayString(booleanList));
b.set(false);
System.out.println(at.get() + forArrayString(booleanList));
b.set(true);
System.out.println(at.get() + forArrayString(booleanList));
booleanList.add(new SimpleBooleanProperty(false));
System.out.println(at.get() + forArrayString(booleanList));
booleanList.remove(3, 5);
System.out.println(at.get() + forArrayString(booleanList));
at.dispose();
}
private String forArrayString(List list) {
return " for " + Arrays.toString(list.toArray());
}
}
You can easily implement the method as follows:
public static BooleanBinding conjunction(ObservableList<BooleanProperty> list){
BooleanBinding and = new SimpleBooleanProperty(true).and(list.get(0));
for(int i = 1; i < list.size(); i++){
and = and.and(list.get(i));
}
return and;
}
I have inserted a list in my j2ME project,designed using LWUIT. The code is as follows
Button btnHome;
Button btnExit;
List list;
setScrollableY(false);
setScrollable(false);
list = new List();
MyRenderer render = new MyRenderer();
list.setListCellRenderer(render);
list.getStyle().setFgColor(0xfaedf2);
list.setSmoothScrolling(true);
list.addSelectionListener(new SelectionListener(){
public void selectionChanged(int i, int i1) {
try {
InformationForm form = new InformationForm();
form.show();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
String[] arrString = builder.getArrName();
System.out.println(arrString.length);
for (int i = 0; i < arrString.length ; i++)
{
list.addItem(arrString[i]);
// System.out.println("item no " + i +" = " +arrString[i] + "added in list");
}
BorderLayout bl=new BorderLayout();
setLayout(bl);
Container holdingContainer=new Container(new FlowLayout(Component.LEFT));
Container c0 = new Container(new BoxLayout(BoxLayout.X_AXIS));
Container c1 = new Container(new FlowLayout(Component.LEFT));
Container c2 = new Container(new FlowLayout(Component.LEFT));
Container footerContainer=new Container(new BoxLayout(BoxLayout.X_AXIS));
c0.addComponent(cityChoice);
c0.addComponent(btnFilter);
//c2.addComponent(list);
c1.setPreferredH(25);
holdingContainer.addComponent(c0);
holdingContainer.addComponent(c1);
getStyle().setBgColor(0x730E36);
// holdingContainer.addComponent(c2);
holdingContainer.setPreferredH(280);
holdingContainer.setScrollableY(true);
addComponent(BorderLayout.CENTER,list);
//addComponent(BorderLayout.WEST,holdingContainer);
footerContainer.getStyle().setMargin(Component.LEFT, 0);
footerContainer.addComponent(btnHome);
footerContainer.addComponent(btnExit);
addComponent(BorderLayout.SOUTH,footerContainer);
The renderer for list is,
public class MyRenderer extends TextArea implements ListCellRenderer{
public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected){
getStyle().setBorder(Border.createEmpty());
getStyle().setFgColor(0xfaedf2);
getStyle().setBgColor(isSelected ? 0x630A2E : 0x730E36);
setText(value.toString());
if (isSelected) {
setFocus(true);
getStyle().setBgTransparency(100);
} else {
setFocus(false);
getStyle().setBgTransparency(0);
}
return this;
}
public Component getListFocusComponent(List list){
return null;}
}
The problem is when on device, i try to scroll the list, the item on which i touched is selected immediatly and the new form for it is opened. I do not able to scroll the list at all. Please help me in solving this problem.
Is it possible you are using a SelectionListener instead of an ActionListener?