I am trying to integrate highcharts in my android app (inside fragment) but I am getting this error every time:
java.util.NoSuchElementException: HIOptions not found in HIChartView
Here is my onCreateView Method:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
parentView = inflater.inflate(R.layout.bar_layout, null);
return parentView;
}
How I am getting chart view:
chartView = parentView.findViewById(R.id.hc);
I am calling chart API to get to data after getting a response, I am setting options but it is giving me the same error, below is the code snippets how am I setting chart:
HIOptions options = new HIOptions();
HIChart chart = new HIChart();
chart.setType("column");
options.setChart(chart);
HIExporting hiExporting = new HIExporting();
hiExporting.setEnabled(false);
options.setExporting(hiExporting);
List<BarChartSeries> seriesList = barChartModel.getSeries();
if (!seriesList.isEmpty()) {
final HIXAxis xAxis = new HIXAxis();
HITitle xAxisTitle = new HITitle();
xAxisTitle.setText(getString(R.string.year));
xAxis.setTitle(xAxisTitle);
XAxisDto xAxisDto = barChartModel.getxAxis();
List<String> stringList1 = xAxisDto.getCategories();
ArrayList<String> xAxisList = new ArrayList<>();
xAxisList.addAll(stringList1);
xAxis.setCategories(xAxisList);
xAxis.setCrosshair(new HICrosshair());
ArrayList<HIXAxis> axes = new ArrayList<>();
axes.add(xAxis);
options.setXAxis(axes);
HIYAxis yAxis = new HIYAxis();
yAxis.setMin(0);
HITitle yAxisTitle = new HITitle();
yAxisTitle.setText(getString(R.string.no_of_cases));
yAxis.setTitle(yAxisTitle);
ArrayList<HIYAxis> yaxes = new ArrayList<>();
yaxes.add(yAxis);
options.setYAxis(yaxes);
HITooltip tooltip = new HITooltip();
tooltip.setHeaderFormat("<span style=\"font-size:10px\">{point.key}</span><table>");
tooltip.setPointFormat("<span style=\"font-size:10px\">{point.key}</span><table>");
tooltip.setFooterFormat("</table>");
tooltip.setShared(true);
tooltip.setUseHTML(true);
options.setTooltip(tooltip);
HIPlotOptions plotOptions = new HIPlotOptions();
HIColumn hiColumn = new HIColumn();
hiColumn.setPointPadding(0.2);
hiColumn.setBorderWidth(0);
plotOptions.setColumn(hiColumn);
options.setPlotOptions(plotOptions);
ArrayList<HISeries> dataSetList = new ArrayList<>();
if (seriesList.size() > 0) {
for (int i = 0; i < seriesList.size(); i++) {
BarChartSeries barChartSeries = seriesList.get(i);
String name = barChartSeries.getName();
List<Data> dataList = barChartSeries.getData();
HIColumn series1 = new HIColumn();
series1.setName(name);
List<String> stringList = xAxisDto.getCategories();
ArrayList<BarEntry> yVals = new ArrayList<BarEntry>();
ArrayList<Long> doubleArrayList = new ArrayList<>();
if (stringList != null) {
for (int j = 0; j < stringList.size(); j++) {
String cat = stringList.get(j);
int count = 0;
for (int ij = 0; ij < dataList.size(); ij++) {
Data data = dataList.get(ij);
if (data.getYear().equalsIgnoreCase(cat)) {
count++;
yVals.add(new BarEntry(ij, data.getCount()));
doubleArrayList.add(data.getCount());
break;
}
}
if (count == 0) {
yVals.add(new BarEntry(yVals.size() + 1, 0));
doubleArrayList.add(0l);
}
}
}
series1.setData(doubleArrayList);
dataSetList.add(series1);
}
}
options.setSeries(dataSetList);
ArrayList<HIColor> hiColors = new ArrayList<>();
hiColors.add(HIColor.initWithHexValue("FF0000"));
hiColors.add(HIColor.initWithHexValue("FFA500"));
hiColors.add(HIColor.initWithHexValue("808080"));
options.setColors(hiColors);
HITitle title = new HITitle();
title.setText("");
options.setTitle(title);
HISubtitle subtitle = new HISubtitle();
subtitle.setText("");
options.setSubtitle(subtitle);
HICredits hiCredits = new HICredits();
hiCredits.setEnabled(false);
options.setCredits(hiCredits);
chartView.setOptions(options);
What am I missing here? Or How to resolve this issue?
I am able to solve the issue.
Follow below steps to resolve the issues:
When you fragment view is visible
Get highchart Id
chartView = parentView.findViewById(R.id.hc);
Set empty options to chartView:
HIOptions options = new HIOptions();
chartView.setOptions(options);
Once you get the data from your API set options to chartView again and call reload method:
chartView.setOptions(options);
chartView.reload();
Add the dependency again
implementation 'com.highsoft.highcharts:highcharts:7.0.3'
in the build.gradle file(app)
In my case It worked Well
i want add subitem in a listview. This is my code
ArrayList<String> mAllData;
private String [] cognomi = {
//my string
};
public void setData() {
mAllData = new ArrayList<String>();
mAdapter = new MySimpleSearchAdapter(this);
for (int i = 0; i < cognomi.length; i++) {
mAdapter.addItem(cognomi[i]);
mAllData.add(cognomi[i]);
}
You can use a pre-defined android layout for this: http://www.javajirawat.com/2013/03/android-listview-tutorial_12.html
At the following code i am loading an ArrayList with data one by one.
This ArrayList is used in an ExpandableListView. So it contains groups and childs.
Every group has a Name and a Description.
Every child has a Name.
Some groups do not have childern.
public class CategoriesExpandableList extends Activity implements OnChildClickListener,
OnGroupClickListener, OnGroupExpandListener, OnGroupCollapseListener {
private static Context mContext;
private ExpandListAdapter ExpAdapter=null;
private ArrayList<ExpandListGroup> ExpListItems;
ArrayList<ExpandListGroup> list=null;
private ExpandableListView ExpandList;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.categoriesexpandable);
ExpandList = (ExpandableListView) findViewById(R.id.ExpList);
ExpListItems = SetStandardGroups();
ExpAdapter = new ExpandListAdapter(CategoriesExpandableList.this, ExpListItems);
ExpandList.setAdapter(ExpAdapter);
ExpandList.setOnGroupClickListener(this);
ExpandList.setOnChildClickListener(this);
mContext=this;
}
public ArrayList<ExpandListGroup> SetStandardGroups() {
ArrayList<ExpandListGroup> list = new ArrayList<ExpandListGroup>();
ArrayList<ExpandListChild> list2 = new ArrayList<ExpandListChild>();
ExpandListGroup gru0 = new ExpandListGroup();
gru0.setName("My Favorites");
gru0.setDescription("My favourite points of interest");
gru0.setItems(list2);
list2 = new ArrayList<ExpandListChild>();
ExpandListGroup gru1 = new ExpandListGroup();
gru1.setName("Essentials");
gru1.setDescription("Very essential points of interest");
gru1.setItems(list2);
list2 = new ArrayList<ExpandListChild>();
ExpandListGroup gru2 = new ExpandListGroup();
gru2.setName("Sights");
gru2.setDescription("Beautiful sights you have to visit");
gru2.setItems(list2);
list2 = new ArrayList<ExpandListChild>();
ExpandListGroup gru3 = new ExpandListGroup();
gru3.setName("Beaches");
gru3.setDescription("Beaches near Agios Nikolaos");
ExpandListChild ch3_0 = new ExpandListChild();
ch3_0.setName("In town");
ch3_0.setTag(null);
list2.add(ch3_0);
ExpandListChild ch3_1 = new ExpandListChild();
ch3_1.setName("Outside town");
ch3_1.setTag(null);
list2.add(ch3_1);
gru3.setItems(list2);
list2 = new ArrayList<ExpandListChild>();
list.add(gru0);
list.add(gru1);
list.add(gru2);
list.add(gru3);
return list;
}
}
I want to know if there is a quick way to load these data at the ArrayList. For example by calling a method like this:
addPoint(String groupname, String groupdescription, String child01)
addPoint("Banks", "Banks and ATMs", "Only banks")
addPoint("Banks", "Banks and ATMs", "Only ATMs")
// Here i have only a group and no children...
addPoint("Sights", "Beautiful sights to visit", "")
public ArrayList<ExpandListGroup> SetStandardGroups() {
ArrayList<ExpandListGroup> list = new ArrayList<ExpandListGroup>();
ArrayList<ExpandListChild> list2 = new ArrayList<ExpandListChild>();
String[][] expandablelist={ {"My Favorites", "My favourite points of interest","","","","","","","","","",""},
{"Essentials", "Very essential points of interest","","","","","","","","","",""},
{"Sights", "Beautiful sights you have to visit","","","","","","","","","",""},
{"Beaches", "Nice beaches","In town","Around town","","","","","","","",""},
{"Banks", "Banks and ATMs","","","","","","","","","",""},
{"Pharmacies", "All pharmacies near you","","","","","","","","","",""},
{"Doctors", "Doctors in case of emergency","Pediatricians","Pathologists","General doctors","Eye doctors","Surgeons","Otorhinolayngologists","Orthopaedists","Gynecologists","Dermatologists","Cardiologists"}
};
for(int i=0; i<=6; i++) {
System.out.println("i= "+i);
ExpandListGroup gru = new ExpandListGroup();
gru.setName(expandablelist[i][0]);
gru.setDescription(expandablelist[i][1]);
for(int j=2; j<=11; j++) {
System.out.println("j= "+j);
System.out.println("length= "+expandablelist[i][j].length());
if(expandablelist[i][j].length()!=0) {
ExpandListChild chld = new ExpandListChild();
chld.setName(expandablelist[i][j]);
chld.setTag(null);
list2.add(chld);
}
}
if(list2!=null) {
gru.setItems(list2);
}
list2 = new ArrayList<ExpandListChild>();
list.add(gru);
}
}
I have founnd a way to load my ArrayList from an Array like you see at the code above.
Thank you for reading about my problem.
I am sure there is a better solution and if i have some time i will try to figure it out.
EQName list calling from the service
JSONArray EQResponseArray = new JSONArray(EQSpecifCompanrison);
int EQResponseSize = EQResponseArray.length();
String[] EQName = new String[EQResponseSize];
for(int i = 0; i< EQResponseSize; i++)
{
JSONObject EQResponseObject = EQResponseArray.optJSONObject(i);
int EQ_ID = EQResponseObject.optInt("EquipmentStatusId");
EQID[i] = EQ_ID;
String EQ_Name = EQResponseObject.optString("EquipmentStatusDescription");
EQName[i] = EQ_Name;
int EQ_PlantID = EQResponseObject.optInt("equipmentParentStatusId");
EQPlantID[i] = EQ_PlantID;
}
I have problem in AddALL section. I think problem in to convert how it will be? Planet constructer takes list items but my list have array list.
ArrayList<Planet> planetList = new ArrayList<Planet>();
Object[] mStringArray = planetList.toArray();
planetList.addAll(EQName);
listAdapter = new PlanetArrayAdapter(getActivity(), planetList);
SpecificList.setAdapter( listAdapter );
i'd like each for row in listview has a spinner. But can not. please help me.
//Setting player
adapter = new SimpleAdapter(this, list, R.layout.custom_listitem_edit,
new String[] { "cat", "duration", "order", "id_pos"}, new int[] {
R.id.spn_edibt_selectcat,
/*R.id.spn_editbt_selectpos,*/
R.id.txt_editbt_dur,
R.id.txt_editbt_order,
R.id.txt_edit_idpos
});
populateList();
setListAdapter(adapter);
static final ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
/* Set thong tin cho listview */
private void populateList() {
cursor_position_mycurrent = dbHelper_position_mycurrent.fetchAllPositionMyCurrentById(id_bt);
startManagingCursor(cursor_position_mycurrent);
Log.e("SO dong lay duoc la", String.valueOf(cursor_position_mycurrent.getCount()));
if (cursor_position_mycurrent != null) {
cursor_position_mycurrent.moveToFirst();
while (cursor_position_mycurrent.isAfterLast() == false) {
HashMap<String, String> tmp = new HashMap<String, String>();
Log.e("DUR", cursor_position_mycurrent.getString(5));
Log.e("DUR", cursor_position_mycurrent.getString(6));
tmp.put("duration", cursor_position_mycurrent.getString(5));
tmp.put("order", cursor_position_mycurrent.getString(6));
tmp.put("id_pos", cursor_position_mycurrent.getString(0));
//Setting spinner category
cursor_position_allposition =dbHelper_position_allposition.fetchAllPositions();
array_spinner_category = new String[cursor_position_allposition.getCount()];
if (cursor_position_allposition != null) {
int i = 0;
cursor_position_allposition.moveToFirst();
while (cursor_position_allposition.isAfterLast() == false) {
array_spinner_category[i] = cursor_position_allposition.getString(0);
cursor_position_allposition.moveToNext();
i++;
}
cursor_position_allposition.close();
}
Log.e("ALL POS", String.valueOf(cursor_position_allposition.getCount()));
Spinner spinner = (Spinner) findViewById(R.id.spn_edibt_selectcat);
int m = 3;//Integer.parseInt(camping.rulesList.getMaxPers().get(camping.tipSel));
String[] array_spinner=new String[m];
for (int indice = 0; indice < m; indice++)
{
if (indice == 0) array_spinner[indice] = String.format("%d persona", indice+1);
else array_spinner[indice] = String.format("%d persone", indice+1);
}
final ArrayAdapter<String> aa = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, array_spinner);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(aa);
list.add(tmp);
cursor_position_mycurrent.moveToNext();
}
}
}