Add a dynamic image in a ListView - java

So, basically i'm working with a ListView, looking like this for the moment :
(source: xooimage.com)
(As a new user I can't post images..)
I add each element of the list like that :
map = new HashMap<String, String>();
map.put("ing_name", "Mozzarella");
listItem.add(map);
map = new HashMap<String, String>();
map.put("ing_name", "Emmental");
listItem.add(map);
I would like to put a different picture for every element, to end up with something like that (I photoshoped it) :
(source: xooimage.com)
I tried some things, but couldn't find out one working.
Does someone know how to do it ?
Thanks. :-)

Try using the Simple adapter class. The below link might be helpful.
Simple adapter example
I hope it helps..

Related

Best Vaadin component for a list of String

My issue is I have a simple List of Strings say
List<String> names = List.of("Frank","Joe","Eva");
All I want is display it on the UI. With some simple code like
ListComponent lc = new ListComponent.setItems(names);
I have tried it with Table which seems to work but code behind it is a bit boilerplate for this simple task(7-8 line of code).
I have tried also the Grid component and it works well when I want to bind a POJO to it , but with String.class type its a nightmare.
Grid<String> listGrid= new Grid<>(String.class) ;
listGrid.setItems(names);
it doesnt work because I have to provide getters for the column, which String.class doesnt have for the value. So I did this:
Grid<String> listGrid= new Grid<>(String.class) ;
listGrid.setItems(names);
listGrid.addColumn(String::toString).setCaption("name");
It works! However unspecified columns also appear in the grid, so now I have 3 columns Byte,Empty,name. And I dont know why. Where are these comes from?
What are the requirements for displaying them? Just to get them on the screen? Is Label enough?
for(String name: names) {
mylayout.addComponent(new Label(name))
}
If you need selection, then maybe ListSelect or ComboBox are the go-to’s.
If you want to avoid the additional columns, one way is to do as was pointed out in a comment, i.e. do removeAllColumns() before you go on creating your own columns.
Another approach would be to do new Grid<>() instead of new Grid<>(String.class). The main difference is that the second constructor uses reflection on the provided class and automatically configures columns for anything that looks like regular Java bean properties.
I would highly prefer to use grid.removeColumnByKey rather than removeAllColumns()
You can also use grid.setColumns to specify order of columns.
I will add link to vaadin documentantion for grid with java examples which is realy helpfull. enter link description here
I did something similar to adding the Strings in TextAreas. Because I needed some formatting, I added the text using StringBuilder.
List<String> details = getDetails();
StringBuilder builder = new StringBuilder();
for (String detail : details) {
TextArea ta = new TextArea();
ta.setSizeFull();
ta.setMaxHeight("100px");
ta.setValue(builder.append(detail).toString());
((Span) content).add(ta);
((Span) content).add(new Hr());
}
The result is like this:
Try out this
final Grid<String> grid = new Grid<>();
grid.setItems(new ArrayList<String>());
grid.addColumn(item -> item).setHeader("Value");

JxMaps possibility to disable Google's default POI

with JxMaps I can show a Google-Map window within Java Swing.
When zooming in, Google shows much details as Restaurants and Shops.
I also can click on those Restaurants and Shops - but that's something I don't want to have in my application.
Anyone having an idea on how to disable it?
I think it might be possible when setting map options:
// Getting the associated map object
map = getMap();
// Creating a map options object
MapOptions mapOptions = new MapOptions();
// Creating a map type control options object
MapTypeControlOptions controlOptions = new MapTypeControlOptions();
// Changing position of the map type control
controlOptions.setPosition(ControlPosition.TOP_RIGHT);
// Setting map type control options
mapOptions.setMapTypeControlOptions(controlOptions);
// Setting map options
map.setOptions(mapOptions);
But I cant find an appropriate option.
Thank you very much
MapOptions doesn't have property that allows to hide POI. But you can create custom map style with hidden default POI. Please take a look example below:
MapTypeStyler styler = new MapTypeStyler();
styler.setVisibility("off");
MapTypeStyle style = new MapTypeStyle();
style.setElementType(MapTypeStyleElementType.ALL);
style.setFeatureType(MapTypeStyleFeatureType.POI);
style.setStylers(new MapTypeStyler[]{styler});
StyledMapType styledMap = new StyledMapType(map, new MapTypeStyle[]{style});
map.mapTypes().set("newStyle", styledMap);
map.setMapTypeId(new MapTypeId("newStyle"));

Username and Pass code using parallel arrays

I am trying to create a pass code and username login for an app that I am designing. At the moment I am required to have four users, and four separate pass codes that are relevant to each user.
this code needs to be run in an android emulator.
Would anyone have a simple array structure that would be easy to follow?
As Hristo said, you should use a HashMap
Map<String, String> myMap = new HashMap<String, String>();
myMap.put("DmcG", "somePassword");
...
String password = myMap.get("DmcG");
Why don't you try using Hashmap? Its structure is < Key, Value >. You can implement it by using the key for username and its value for password. Hope that helps!

Android - How to define sets of drawable images to be shown in edittext or text view

I'm trying to do the next thing - let's say i have a menu with 5 drawable images (could be more but that's not the point), now when a user press on one drawable then it will be shown next a text that is already shown in the edittext.
Also I would like to allow the user add as many drawables as he wants.
So what i do understand is the next code lines -
Using map and defines the pairs of keyword and matching drawable -
private HashMap<String, Integer> emoticons = new HashMap<String, Integer>();
emoticons.put("[-smile-]", R.drawable.smile);
emoticons.put("[-tongue-]", R.drawable.tongue);
emoticons.put("[-cool-]", R.drawable.cool);
emoticons.put("[-sad-]", R.drawable.sad);
emoticons.put("[-cry-]", R.drawable.cry);
fillArrayList();
private void fillArrayList() {
Iterator<Entry<String, Integer>> iterator = emoticons.entrySet().iterator();
while(iterator.hasNext()){
Entry<String, Integer> entry = iterator.next();
arrayListSmileys.add(entry.getKey());
}
}
First of all - I've decided to define the keywords like the next pattern - [-keyword-] - because I assume in that way it will be much more easy to get the keywords from the String.
Now, the thing that I'm getting stuck in, is how should I read the String, and how to change the keywords from the String into the drawable.
So let's say the user want to write the next line (using the drawables) -
I am [-smile-] everything [-cool-]
So what I try to do is, something that can read this string and when it getting into [-keyword-], then it knows to show it to the user as drawable from the map pairs.
Thanks for any kind of help
If I'm working out your problem correctly you want to use "smileys" in your text?
You can use HTML in TextViews and display the images with image tags.
yourTextView.setText(Html.fromHtml("I am <img src='img_smile'>smile</img> everything <img src='img_cool'>cool</img>"));

How do you send checkbox data in Jsoup

I am trying to post checkbox data with Jsoup and am having a little trouble. I thought that when multiple checkboxes are selected, they are sent as an array to the server but maybe that is not the case?
This is what I thought was correct:
HashMap<String, String> postData = new HashMap<String, String>();
postData.put("checkbox", "[box1,box2,box3]");
Jsoup.connect("somesite").data(postData).post();
This does not seem to work properly. However, if I send only a single checkbox then I get my expected results leading me to believe my understanding of how checkbox form data sends is incorrect.
This works:
postData.put("checkbox", "box2");
Maybe HashMap is the wrong type to use. According to the Jsoup documentation I could just call .data(key, value) multiple times but I was hoping for something a little cleaner than that.
If you have multiple checkboxes, then presumably each checkbox has its own name attribute. You should then call .data(name, value) for each such name.
AFAIK there's no way to "collapse" these calls to data into a single call.
Maybe You can try something like the following ?
HashMap<String,String> paramHM=new HashMap<String,String>();
ArrayList<String> checkboxVal=new ArrayList<Strnig>();
/ .. put request.getParametersValues() in this arraylist
org.jsoup.Connection jsoupConn=Jsoup.connect(web_api).data(paramHM);
// Multiple Call that
for(String item:checkboxVal){
jsoupConn=jsoupConn.data("checkbox",item);
}

Categories