Need to set column label dynamically in JFreeChart - android

Please see attached screeshot. i want to set label dynamically for X axis. Currently is says Test1,Test2,Test3,Test4..if i want to set a category array dynamically how can i do that? i mean i want to set category like House Expense,Office Rent, Food...etc. Here is screenshot and code.
http://www.screencast.com/t/lak24QQvfM3
Here is the bar chart code. see line between 86-90.
http://pastebin.com/MXq4zTbw
Can anyone help me with that? If anything is not clear please ask.
Thanks in advance.

Replace your createDataset() with something like this:
private static CategoryDataset createDataset() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(40.0,"Expediture","House");
dataset.addValue(30.0,"Expediture","Office Rent");
dataset.addValue(-20.5,"Expediture","Food");
dataset.addValue(30.0,"Expediture","Other");
dataset.addValue(6.0,"Expediture","Etc");
return dataset;
}

Related

Is there a Simpler way to Show ListView Item activities when you have lots of items?

I have a listView which get information from the XML(listview of drinks and title, description) I have made onClick but i wanted to know if there is a simpler way of showing the activities for each item on mylistView. I have more than 10 items on my listView does that mean I have to Create more than 10 new Activities_xml each with same layout Just displaying more Information about the Clicked item. I'm going to have other parts of the Android App to have more ListViews(maybe 10 listView which will equal 100 Activities in my Layout Folder). possibly having minimum of 10 activities per listView.
Would be helpful if you let me know if this is right way to do it or if there's a simlper way. thank you
here is an example code on how you should, details will change to exactly what u need, and what names you put to stuff, but that's the base idea of it.
make sure to check the Bundle docs: https://developer.android.com/reference/android/os/Bundle.html
to launch the "drink details"
Intent i = new Intent(this, DetailsActivity.class)
i.putExtra("drinkName", "coca");
i.putExtra("drinkSize", "500ml");
startActivity(i);
then on the details activity
onCreate(Bundle savedInstance){
super.onCreate(savedInstnace);
String drinkName = getIntent().getExtras().getString("drinkName");
String drinkSize = getIntent().getExtras().getString("drinkSize");
// then you can assign those `String` values to your `TextView` on the layout
}

How can I customize google suggestions?

I want to customize suggstions
which I get throught suggestion provider. I vant to add there one image to the left and one sub title. it should look like this:
Is that way to change the layout of them? Thanks for all of the answers.
Please put any response of google suggestion api that have images.
Not sure whether that google suggestion responce gives images also or not. If google suggestion API gives images in responce then yes you can do it. But if they not then you can not able to put images.
Yes, you can put any static images and static description that is common for all the suggestion list. But not able to set any dynamic images if the google suggestion not provided.
hope you got the point.
I find it out, it can be done with adding 2 more lines:
private static final String[] SEARCH_SUGGEST_COLUMNS = {
BaseColumns._ID,
SearchManager.SUGGEST_COLUMN_TEXT_1,
SearchManager.SUGGEST_COLUMN_TEXT_2,//this
SearchManager.SUGGEST_COLUMN_ICON_1,//this
SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID
};
and you can add the image simply to cursor like this:
cursor.addRow(new Object[] { -1, "Plants", "Search Plants", R.drawable.pin_bank,0});
hope it helps

Sorting Custom ListView with Image and Text items

I have custom ListView in my android application. It consists images and title and content like subtitle and price. Here I want to sort my ListView in price basis. Any one can help me? How to sort the ListView. For example pls refer the following link if possible to sort the list in degree basis...
http://www.codeproject.com/Articles/507651/Customized-Android-ListView-with-Image-and-Text
You need to sort the data structure before setting in the listview. it is only the possible way i think
First sort your data like this
Collections.sort(myList, new Comparator<WeatherData>() {
#Override
public int compare(WeatherData lhs, WeatherData rhs) {
return lhs.degree.compareTo(rhs.degree);
}
});
and then apply it to your adapter.

Grouping string ListView on Android?

I have string like this :
you
me
i
me
i
i
you
me
me
I want to group that string in my ListView like this :
you (2)
me (4)
i (3)
and if I click "you (2)", show ListView again like this :
you
you
Can you help me?
First you need to sort your list adapter. For sorting this will be useful for you http://www.anddev.org/code-snippets-for-android-f33/alphabetical-listview-in-android-t56983.html
Then implement expandable list
As Dheeresh Singh said, please work on some code and then we can help more. Thanks

Searchable String-Array, Android?

How can I search through an String-Array? I've got an dictionary app and the words are saved in a String-Array and it would be user-friendlier, if you could search for the word you want to look up, instead of looking its way to the word. Can somebody help?
Thanks.
You can try using an ArrayList instead. Then you can see if the word is in your 'dictionary' by using the contains method, ex:
ArrayList <String> myDictionary = new ArrayList<String>();
myDictionary.add(new String("foo"));
myDictionary.add(new String("bar"));
...
// To check if the word exists in your dictionary.
if (myDictionary.contains(new String("word_to_look_up")))
{
}
Not entirely sure what you are looking for- do you want to see if the word is in the array, or what is the goal? If you want the user to get to the word faster, changing the string-array will not help the UI jump to the right place.
If you want it to be like Google suggest you could take your array and make a tree data object, which each node representing a letter in a word. Then if the user types a, you go into that node and offer possible words.
You may use the Arrays.binarySearch() method to search an element from the sorted array.

Categories

Resources