I don't know why i have tow errors one at ClickListener() and ShowListener()? I am trying to like OnItemClickListener but for MeowBottomNavigation
getSupportActionBar().hide();
bottomNavigation =findViewById(R.id.bottomNavigation);
bottomNavigation.add(new MeowBottomNavigation.Model(1, R.drawable.ic_baseline_message));
bottomNavigation.add(new MeowBottomNavigation.Model(2, R.drawable.ic_settings));
bottomNavigation.add(newMeowBottomNavigation.Model(3,R.drawable.ic_baseline_account_circle_24));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new FragmentChatt()).commit();
bottomNavigation.setOnClickMenuListener(new MeowBottomNavigation.**ClickListener()** {
public void onClickItem(MeowBottomNavigation.Model item) {
//Toast.makeText(getApplicationContext(),"Clicked item"+item.getId(),Toast.LENGTH_SHORT).show();
}
});
bottomNavigation.setOnShowListener(new MeowBottomNavigation.**ShowListener()** {
public void onShowItem(MeowBottomNavigation.Model item) {
Fragment select_fragment=null;
switch (item.getId()){
case ID_CHAT:
select_fragment=new FragmentChatt();
break;
case ID_SETTINGS:
select_fragment=new FragmentSettengs();
break;
case ID_ACOUNT:
select_fragment=new FragmentAcount();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,select_fragment).commit();
}
});
}
}
I know this is an old post now, but for anyone who's still having the same problem check your module implementation in build.gradle file.
Here's the a dependency that worked for me:
dependencies {
implementation 'com.etebarian:meow-bottom-navigation-java:1.2.0'
}
You can also check their github:
Documentation
But that is a deprecated solution, so here's the new one they recommend New Documentation.
If you want to use the new solution, you need to implement the dependency:
dependencies {
implementation 'com.etebarian:meow-bottom-navigation:1.3.1'
}
And change the setOnShowListener and setOnClickMenuListener methods with:
bottomNavigation.setOnClickMenuListener(new Function1<MeowBottomNavigation.Model, Unit>() {
#Override
public Unit invoke(MeowBottomNavigation.Model model) {
// YOUR CODES
return null;
}
});
bottomNavigation.setOnShowListener(new Function1<MeowBottomNavigation.Model, Unit>() {
#Override
public Unit invoke(MeowBottomNavigation.Model model) {
// YOUR CODES
return null;
}
});
Related
I'm trying to find an easy way of linking a TreeView of type Download to an ObservableList of the same type.
MainController.java
public class MainController {
private ObservableList<Download> downloads = FXCollections.observableArrayList();
#FXML private TreeView<Download> $TreeDownloads;
#FXML
public void initialize() {
$TreeDownloads.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
$TreeDownloads.setNodeOrientation(NodeOrientation.LEFT_TO_RIGHT);
$TreeDownloads.setShowRoot(false);
downloads.addListener(new ListChangeListener<Download>() {
#Override
public void onChanged(Change<? extends Download> c) {
if (c.wasAdded()) {
addDownloads(c.getAddedSubList());
}
if (c.wasRemoved()) {
//
}
}
});
downloads.add(new Download("3847"));
downloads.add(new Download("3567"));
downloads.add(new Download("2357"));
}
private void addDownloads(List<? extends Download> downloads) {
downloads.forEach(download -> {
TreeItem<Download> treeItem = new TreeItem<>(download);
$TreeDownloads.getRoot().getChildren().add(treeItem);
new Thread(download::start).start();
});
}
private void removeDownloads(List<? extends Download> downloads) {
// remove treeitems from the treeview that hold these downloads
}
}
Download.java
public class Download {
private DoubleProperty progress = new SimpleDoubleProperty(0D);
private StringProperty id = new SimpleStringProperty("");
public Download(String id) {
this.id.set(id);
}
public void start() {
while (progress.getValue() < 1) {
try {
Thread.sleep(1000);
progress.add(0.1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
#Override
public String toString() {
return id.getValue();
}
}
How do i implement a remove by Object(Download) mechanism, and is there an easier way to bind observablelist's items to a treeview?
Still not entirely certain what the exact problem is, all pretty straightforward:
First off, your list change listener implementation is incorrect, it must advance the subChanges before accessing its state (you did run your posted code, or not ;)
downloads.addListener(new ListChangeListener<Download>() {
#Override
public void onChanged(Change<? extends Download> c) {
// this while was missing
while (c.next()) {
if (c.wasAdded()) {
addDownloads(c.getAddedSubList());
}
if (c.wasRemoved()) {
// accessing the list of removed elements is .. plain standard api
removeDownloads(c.getRemoved());
}
}
}
});
Now implement the removal of the corresponding treeItems:
private void removeDownloads(List<? extends Download> downloads) {
// remove treeitems from the treeview that hold these downloads
List<TreeItem<Download>> treeItemsToRemove = treeDownloads.getRoot().getChildren().stream()
.filter(treeItem -> downloads.contains(treeItem.getValue()))
.collect(Collectors.toList());
treeDownloads.getRoot().getChildren().removeAll(treeItemsToRemove);
}
Asides:
java naming conventions use lowercase letters for members: treeDownloads (not $TreeDownloads)
the "verifiable" in MCVE implies being runnable as-is: the poster should be the first to verify that ;) yours wasn't due to incorrect implementation of the listener
the "minimal" in MCVE means leaving out everything that's not needed: f.i. calling the threading code - which in your first snippet was particularly distracting because violating fx' threading rule is a rather common error
I am trying to develop a plugin for Intellij IDEA, I am working with SDK 129.451.
The issue I have is that I can't persist the user data like some list items he can input in the plugin and have the data back after the IDE restarts..
I am using PersistentStateComponent to persist the data, the getState() method seems to be called but the loadState() method doesn't.
Here is a sample class that extends PersistentStateComponent:
#State(name = "Test", storages = {#Storage(file = StoragePathMacros.APP_CONFIG+"/other.xml"
)})
public class Test implements PersistentStateComponent<Element> {
String ceva;
public Test() {
ceva = "sad";
System.out.println("constr");
}
public String getCeva() {
return ceva;
}
public void setCeva(String ceva) {
this.ceva = ceva;
}
public void loadState(Element state) {
System.out.println("cstate load");
ceva = (String) state.getContent().get(0);
}
public Element getState() {
System.out.println("cstate retu");
Element configurationsElement = new Element("testtt");
configurationsElement.addContent(ceva);
return configurationsElement;
}
}
Also I added this class in plugin.xml here:
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceImplementation="ro.catalin.prata.testflightuploader.controller.Test"/>
<!-- Add your extensions here -->
<toolWindow id="TF Uploader" secondary="true" icon="/general/add.png" anchor="right"
factoryClass="ro.catalin.prata.testflightuploader.view.TFUploader">
</toolWindow>
</extensions>
And I also have a tool window class:
public class TFUploader implements ToolWindowFactory {
private JButton buttonAction;
private ToolWindow myToolWindow;
final Test test = ServiceManager.getService(Test.class);
public TFUploader() {
// I assume it should print the saved string but it doesn't
System.out.println(test.getCeva());
buttonAction.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// if I click a button I am setting some new value to the string I want to save
test.setCeva(test.getCeva() + "-dddddd+");
}
});
}
Ok so, if I close the app or minimize it, the getState method gets called as I expected.. but when I open the app, the loadState method doesn't get called.. can somebody help me how I can solve this?
I already read this but it doesn't seem to help me to much. Also I want to use PersistentStateComponent as I want to save objects more complex than a simple String.
Thank you in advance!
Ok, I made it! :)
I don't know exactly what the issue was but I changed the Test class to this:
#State(
name = "Test", storages = {
#Storage(
id = "other",
file = "$APP_CONFIG$/testpersist.xml")
})
public class Test implements PersistentStateComponent<Test> {
String ceva;
public Test() {
ceva = "sad";
System.out.println("constr");
}
public String getCeva() {
return ceva;
}
public void setCeva(String ceva) {
this.ceva = ceva;
}
public void loadState(Test state) {
System.out.println("cstate load");
XmlSerializerUtil.copyBean(state, this);
}
public Test getState() {
System.out.println("cstate retu");
return this;
}
}
And in the TFUploader I changed the way I loaded the Test class to this:
final Test test = ServiceManager.getService(Test.class);
I hope it helps others..
I have already commented here but will say again that in my case loadState(MyService state) wasn't called because of lack of getter and setter for stateValue from this example:
class MyService implements PersistentStateComponent<MyService> {
public String stateValue;
public MyService getState() {
return this;
}
public void loadState(MyService state) {
XmlSerializerUtil.copyBean(state, this);
}
}
In my case I was getting a NullPointerException even before loadState was getting called. Similar to your code above I used an Element class as the state class. I had a constructor with some parameters in Element class. This was the problem as the framework could not create an instance of my state class. I tried to add a blank constructor without any parameters. This worked.
I'm having trouble to adding input validation for a double in wicket when useing an ajaxEditableLabel.
This is my code: (item is a listitem from a listview)
item.add(new AjaxEditableLabel("myDouble", new Model(myObject.getMyDouble())) {
#Override
protected void onSubmit(AjaxRequestTarget target) {
super.onSubmit(target);
myObject.setMyDouble(new Double(getEditor().getInput())); //here it fails to read the input when a use enters a wrong number
//Do something when it's a double
}
});
How can I add a validator to this component to check wheter this a double value?
At the moment I'm using:
Double.parseDouble(myval);
With try catch...
But this also needs the input string to be changed because of , and .
There should be a wicket way to validate this input?
Edit**:
Maybe I have to add NumericTextField to this component but I don't understand how.
Check this:
Java:
public class MyPage extends WebPage {
private List<Double> list = Arrays.asList(2013.0, 100.500);
public MyPage() {
final FeedbackPanel feedback = new FeedbackPanel("feedback");
feedback.setOutputMarkupId(true);
add(feedback);
ListView<Double> items = new ListView<Double>("items", new PropertyModel(this, "list")) {
#Override
protected void populateItem(ListItem<Double> item) {
item.add(new AjaxEditableLabel("item", item.getModel()) {
#Override
protected void onSubmit(AjaxRequestTarget target) {
System.out.println(Arrays.toString(list.toArray()));
target.add(feedback);
super.onSubmit(target);
}
#Override
protected void onError(AjaxRequestTarget target) {
target.add(feedback);
super.onError(target);
}
}.add(new IValidator<Object>() {
#Override
public void validate(IValidatable<Object> validatable) {
String in = String.valueOf(validatable.getValue());
try {
Double.parseDouble(in.replace(".", ","));
} catch (Exception ignore) {
try{
Double.parseDouble(in.replace(",", "."));
}catch (Exception e){
ValidationError error = new ValidationError(String.format("`%s` is not a Double", in));
validatable.error(error);
}
}
}
}));
}
};
add(items);
}
}
Markup:
<div wicket:id="feedback"/>
<ul wicket:id="items">
<li wicket:id="item"></li>
</ul>
The validator above made just for demonstration, in real code I suggest to create a separate class (not an anonimous class).
I solved by changing getInput to getConvertedInput(); This was my old way of solving it.
Using getModelObject() is better and since the Type is set to Double this is better.
I've also changed the type to Double. .setType(Double.class
item.add(new AjaxEditableLabel("myDouble", new Model(myObject.getMyDouble())) {
#Override
protected void onSubmit(AjaxRequestTarget target) {
super.onSubmit(target);
myObject.setMyDouble((Double)getEditor().getModelObject())); //changes here!!!
//Do something when it's a double
}
}.setType(Double.class));
I have an xml file in my RCP application. I am displaying it to user using FormEditor.
public class MyFormEditor extends FormEditor implements IResourceChangeListener{
public MyFormEditor(){
ResourcePlugin.getWorkspace.addResourceChangeListener(this);
...
}
#Override
public void resourceChanged(IResourceChangeEvent event){
int type = event.getType();
switch(type){
IResourceChangeEvent.PRE_DELETE:
IResourceChangeEvent.PRE_CLOSE:
this.close(true);
break;
IResourceChangeEvent.POST_CHANGE:
System.out.println("Resource is change.");
break;
default:
break;
}
}
#Override
public void dispose(){
ResourcePlugin.getWorkspace.removeResourceChangeListener(this);
super.dispose();
}
}
IResourceChange.POST_CHANGE event gets triggered when I save resource or I update the resource from SVN repository.
Under IResourceChange.POST_CHANGE how to determine resource is updated from SVN?
I tried following thing but it didn't work for me.
IResourceDelta delta = event.getDelta;
int flags = delta.getFlags();
boolean sync = (flags & IResourceDelta.SYNC) != 0;
if(sync){
System.out.println("Resource updated from server.");
}
Do let me know if you need any other info.
Like lots of askers on SO, I'm relatively new to java and have attempted to teach myself android programming with some decent success. I'm sure this is trivial to someone with actual knowledge on the subject. I'm working on a app that attempts to fetch data from the net and 'returns true' if you get the data and 'returns false' if it doesn't. I want to do something when it returns false but can't figure out how to properly handle the response. Right now, I just ignore the response an do nothing. Any help?
public void onBackPressed() {
Someclass.getinfo().maybeShowInfo(this);
finish();
}
What I would like to do is something like (in pseudo code)
public void onBackPressed() {
Someclass.getinfo().maybeShowInfo(this);
// if false is returned
// do something
// else
// finish();
}
public void onBackPressed() {
boolean result = Someclass.getinfo().maybeShowInfo(this);
if (result) {
finish();
} else {
// do something else
}
}
It looks to me like you've combined two things that must be separate. Make fetching the data and displaying two methods, by two classes.
private InfoDao infoDao; // This is a class that gets the data; it's a member of the class with the onBackPressed() method
public void onBackPressed() {
Info info = this.infoDao.find();
if (info != null) {
displayInfo();
}
}
public void onBackPressed()
{
boolean result = Someclass.getinfo().maybeShowInfo(this);
if (result = false)
{
//do work for false response;
}
else
{
finish();
}
}
don't forget that you have to make your Someclass.getinfo() return true if it succeded and false if it didn't.