I have 4 simple buttons that interact with a listview. If you click a certain button you can go one down, one up, to the start and to the end of the listview. So each button has a different onAction method:
(Buttons: previous, next, end, start)
public void toNext(){
list.getSelectionModel().selectNext();
}
public void toPrevious(){
list.getSelectionModel().selectPrevious();
...
But now I want to disable the buttons if they can't go to the start, end, up or down. I tried to do the following by adding this code to the method toPrevious (example):
previous.setDisable(list.getSelectionModel().getSelectedIndex() == 0)
This code does disable the button but it won't enable it when you can go to the previous string in the listview. Does anyone has a simple solution for this?
You can use a binding:
previous.disableProperty().bind(
list.getSelectionModel().selectedIndexProperty().isEqualTo(0));
next.disableProperty().bind(
list.getSelectionModel().selectedIndexProperty().isEqualTo(
Bindings.size(list.getItems()).subtract(1)));
Related
So I got following problem:
I'm currently developing a sensor app and I'd like to check if the sensors are available or not. If they aren't, I want to change the color of a button (which starts an activity where the value of the sensor is being displayed) to grey.
Sadly, I can't just change the background color of the button because I'm using the Circle Button Library by Markushi.
This button looks like this:
<at.markushi.ui.CircleButton
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/gyroscope"
app:cb_color="#color/colorMain"
app:cb_pressedRingWidth="8dip"
android:id="#+id/gyroscope"
android:layout_alignLeft="#+id/temperature"
android:layout_alignStart="#+id/temperature"
android:layout_below="#+id/title"/>
As you can see this attribute defines the color.
app:cb_color="#color/colorMain"
My Question is: How can I change this color programmaticly in this method?
public void testSensors() {
if (testManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
}
}
EDIT:
setColor doesn't really work. There is this border left. (see image)
Also: I'm using #616161 as the new color.
EDIT2:
Found out, that the border is caused by the transparent circle thing which gets bigger, when the button is pressed. So basically removing this circle thing will be fine. I try to find an answer on my own :)
CircleButton button;
button = (Button)findViewById(R.id.buttonId);
public void testSensors() {
if (testManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
button.setColor(Color.parse("#000000"));
}
}
If you are using normal button then
button.setBackgroundColor(ContextCompat.getColor(context,R.color.colorAccent));
You can use
1) Color.parse("#000000")
2) ContextCompat.getColor(context,R.color.yourColor)
You can use the setColor() method of the circleButton, as you can see from the source code here .
So basically what you need to do is get a reference to your circle Button, using the findViewById method of your activity. then
public void testSensors() {
if (testManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
myCircleButton.setColor(Color.parse("#000000"));
}
}
Also if you are seeing the pressed ring, then that means the state of the button is somehow in the pressed state, so try setting it o false using the setPressed(false) method.
To answer this problem (if anyone has the same):
You can set the animation to 100. This somehow disables the circle.
For some reason the color of the button has now a fixed color (dark grey) but scince this is fine to me and I don't want to cry under my table, I just let it be and move on with my project.
mCircleButton.setAnimationProgress(100);
Thank you all so much for your help! :)
I have implemented a JFace Wizard with 2 WizardPages.
By default, the first WizardPage has these 4 Buttons:
Back (disabled)
Next (focused)
Cancel
Finish (disabled)
Now I want to set the default focus on the Cancel Button. How do I do that?
Removing the focus and setting it to some Control of the page's content would also be ok.
I tried setting the focus to a Button in the content layout of the WizardPage, but this only sets me a second focus on the immediateButton. The focus on the Next button is still there, and the Next button reacts to pressing enter, which is what I want to avoid.
#Override
public void setVisible(boolean visible) {
super.setVisible(visible);
if (visible) {
immediateButton.setFocus();
}
}
How can I access the Dialog buttons and change their focus?
The Next button does not actually have focus, rather it is the Shell Default button.
The logic in WizardDialog makes either Next or Finish the default button and there does not seem to be a way to change this.
You may be able to override this by calling getShell().setDefaultButton(button) in your wizard page.
Update: Testing this you can do it in setVisible but you need to use Display.asyncExec to make the code run at the right time:
final Shell shell = getShell();
shell.getDisplay().asyncExec(() -> shell.setDefaultButton(immediateButton));
above is for Java 8, for Java 7 or earlier:
shell.getDisplay().asyncExec(new Runnable()
{
#Override
public void run()
{
shell.setDefaultButton(immediateButton);
}
});
Hi am working on an android application. And am using a listview in some of my activities.
The problem is all of my listviews displayed are much longer so that the user needs to scroll the whole list to go for the last item.
Am trying to implement a pagination for this, like at first say only 20 items need to displayed on the listview. And at the end of my listview i need a titlebar which have next & previous buttons and on clicking on next button the listview will load the next records from 21st to 40 and so on.
Am using java rest webservice to load the listview.
Can anyone give me a good suggestion for solving my problem.?
Solution 1:
You can load all the data at once if its not TOO MUCH, store it locally & then you can navigate in that locally stored data. Define some variables like StartPoint & EndPoint & get the desired data from that stored data. Increment decrement the values of StartPoint & EndPoint by using the PreviouButton & NextButton.
Solution 2:
Get only the desired data from your data source for example 10 records each time when a Navigation button is clicked.
I suggest than you load list data in a custom Adapter class that extends BaseAdapter class. Like #oriolpons suggested, you should add a footer view, and when you click on button next call some method that is fetching next for example 20 rows, and then add them in your adapter object and call notifyDataSetChanged().
For example
private OnClickListener mListener = new OnClickListener() {
public void onClick(View v) {
ArrayList<YourObject> al = getSomeData(int startRow, int endRow);
MyCustomAdapter adapter = new MyCustomAdapter();
for(YourObject a : al)
adapter.add(a);
getListView.setAdapter(adapter);
notifyDataSetChanged();
}
};
Hope this helps.
The easiest solution is to add a footer view to the listview. And on the item click listener you can see if it is the last position (load more items), or not
//add the footer before adding the adapter, else the footer will not load!
View footerView = ((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listfooter, null, false);
this.getListView().addFooterView(footerView);
#Tijo . Refer this site http://www.androidhive.info/2012/03/android-listview-with-load-more-button/. You can have a button which would call the execute method of Async task and that will load the remaining list for you.
At the moment I am using this to call the TabHost activity to change tabs:
public void switchTab(int index){
MintTrack ParentActivity;
ParentActivity = (MintTrack) this.getParent();
ParentActivity.getTabHost().setCurrentTab(3);
}
This works well, however, the WebView item in tab "3" remains unfocused, until i touch it...
I need to programatically simulate a click on tab 3 then, as clicking the tab automatically places the focus on the webview... Any ideas?
Try this:
getTabHost().getTabWidget().getChildAt(3).performClick();
I'm not sure if it will work, but you can try requesting focus for the child at index 3.
ParentActivity.getTabHost().getTabWidget().getChildAt(3).requestFocus();
I apologize if this question is too basic, but I just can't figure out how to do this. I have a SWT TableFolder with two tabs, and I need to determine which of those two tabs are currently active, as it effects the behavior of another part of the program. Is this possible? Thank you in advance.
To you mean the org.eclipse.swt.widgets.TabFolder (CTabFolder)?
If yes add an eventlistener to your TabFolder(CTabFolder object
tabFolder.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent event) {
tabFolder.getSelection()[0]; // This should be your TabItem/CTabItem
}
});
If you simply have a javax.swing.JTabbedPane then calling
yourJTabbedPaneVariableName.getSelectedIndex()
gives you the index of the selected Tab