• What do you need help with? Version 5
    5,752 replies, posted
I'm having a problem with Android and the ListView object. I'm using a custom arrayAdapter that calls row.setBackgroundResource(colorid) in the getView(int pos, View row, ViewGroup parent) method. The problem appears if i start to scroll around. Sometimes the background resource disappears and appears. I already tried it with: [code]row.setDrawingCacheEnabled(true);[/code] But it hasn't changed anything. Anyone got some suggestions on how to fix this? [thumb]http://i.imgur.com/JoKvWn2.png[/thumb]
[QUOTE=SiPlus;39435342]What about this? [code] const char grades[] = "FFFFFDCBAAA"; char grade = grades[p / 10]; [/code][/QUOTE] That's a pretty cool way of doing it.
[QUOTE=Dr Magnusson;39434854]If anyone's run into the same problem, it's usually because "that" in this context has the const modifier attached to it which means that it is not allowed to be modified. The method reciprocal does not have the const modifier which means that it makes no promises about whether the object is going to be modified by calling that function. Calling the mutable method of a const object is not allowed, causing this error.[/QUOTE] Yup, I should've declared Quaternion::reciprocal as a const method, [code]Quaternion Quaternion::reciprocal() const { return this->conjugate() / pow( this->norm(), 2 ); }[/code]
[QUOTE=Mozartkugeln;39436663]That's a pretty cool way of doing it.[/QUOTE] Doesn't look particularly pretty, and imagine doing that when the lower limit of a grade is something like 83.
[QUOTE=ArgvCompany;39436776]Doesn't look particularly pretty, and imagine doing that when the lower limit of a grade is something like 83.[/QUOTE] That was for the current case, not all cases. And it is assumed that 0<=p<=109, otherwise there will be wrong data or access violation.
[QUOTE=SiPlus;39436839]That was for the current case, not all cases. And it is assumed that 0<=p<=109, otherwise there will be wrong data or access violation.[/QUOTE] If you did bounds checking for p before that it'd be actually a somewhat sane way of doing it in this case, but as you noted you're not. [editline]1st February 2013[/editline] The original code, of course, can just happily ignore any bounds as -45 is still not equal to or greater than fifty.
[QUOTE=esalaka;39437024]If you did bounds checking for p before that it'd be actually a somewhat sane way of doing it in this case, but as you noted you're not.[/QUOTE] It's not full function, it's a little part of it. And range validation should happen at input validation stage, not at grade selection stage.
I've been trying to get SDL 2.0 working on Ubuntu 12.10, however I seem to have ran into some trouble in the linking stage. I've written my own CMake file, however it doesn't seem to work just yet. [cpp]cmake_minimum_required(VERSION 2.6) project(sdl_dungeon) if(CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_BUILD_TYPE Debug) endif() set(EXECUTABLE_NAME "SDL_dungeon") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules") find_package(SDL2 REQUIRED) if(SDL2_FOUND) include_directories(${SDL2_INCLUDE_DIR}) target_link_libraries (${EXECUTABLE_NAME} ${SDL2_LIBARY}) endif(SDL2_FOUND) add_executable(${EXECUTABLE_NAME} system/menustate.cpp system/gamestate.cpp system/statemanager.cpp main.cpp) install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin) add_subdirectory(system) add_subdirectory(world) add_subdirectory(audio) add_subdirectory(input) add_subdirectory(graphics)[/cpp] Can anyone see what's wrong? [editline]1st February 2013[/editline] The CMake stage seems to go fine, it also seems like FindSDL.cmake is able to find the libaries, according to the CMakeCache.txt. [editline]1st February 2013[/editline] :O After 2 days of hard work and desperation, I fixed it with the following CMakeLists.txt [cpp] cmake_minimum_required(VERSION 2.6) project(sdl_dungeon) if(CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_BUILD_TYPE Debug) endif() set(EXECUTABLE_NAME "SDL_dungeon") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules") add_executable(${EXECUTABLE_NAME} system/menustate.cpp system/gamestate.cpp system/statemanager.cpp main.cpp) find_package(SDL2 REQUIRED) if(SDL2_FOUND) include_directories(${SDL2_INCLUDE_DIR}) target_link_libraries(${EXECUTABLE_NAME} ${SDL2_LIBRARY}) endif(SDL2_FOUND) install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin) add_subdirectory(system) add_subdirectory(world) add_subdirectory(audio) add_subdirectory(input) add_subdirectory(graphics) [/cpp] [editline]1st February 2013[/editline] The difference is that I wrote SDL2_LIBARY instead of SDL2_LIBRARY
[QUOTE=Richy19;39426214]if you mean this: [code]int i = x<5 ? 1 : 2;[/code] its effectively the same as: [code]int i; if(x < 5) i = 1; else i = 2; [/code] the way its used is: (conditional) ? true statement : false statement; the only use it has is to make your code shorter[/QUOTE] Why does this work then, shouldn't i get an error while compiling for mismatched types(boolean and string) [code] boolean IsItRegistered; public String toString() { return String.format("Letter is %s",((IsItRegistered) ? "Registered" : "Not Registered")); } [/code]
No, it's basically like having this method: [cpp]String IsItRegistered(){ if(IsItRegistered) { return "Registered"; } return "Not Registered"; }[/cpp]
[QUOTE=RandomDexter;39438869]Why does this work then, shouldn't i get an error while compiling for mismatched types(boolean and string) [code] boolean IsItRegistered; public String toString() { return String.format("Letter is %s",((IsItRegistered) ? "Registered" : "Not Registered")); } [/code][/QUOTE] What? Why would the data type of the variable in the condition matter?
[QUOTE=Gulen;39438901]No, it's basically like having this method: [cpp]String IsItRegistered(){ if(IsItRegistered) { return "Registered"; } return "Not Registered"; }[/cpp][/QUOTE] Oh oh, i see, much obliged :)
[QUOTE=mkp;39436116]I'm having a problem with Android and the ListView object. I'm using a custom arrayAdapter that calls row.setBackgroundResource(colorid) in the getView(int pos, View row, ViewGroup parent) method. The problem appears if i start to scroll around. Sometimes the background resource disappears and appears. I already tried it with: [code]row.setDrawingCacheEnabled(true);[/code] But it hasn't changed anything. Anyone got some suggestions on how to fix this? [/QUOTE] Mh i think i fixed it. Now i set a drawable background resource, not a color and it works. Now it looks like this: [thumb]http://i.imgur.com/seIFpz6.png[/thumb]
[QUOTE=Meatpuppet;39419414]I think I'll just get rid of MenuItem altogether. [editline]31st January 2013[/editline] Ok here is my code now: Text.h [cpp] class Text { public: .... void Text::highlightRectOutline(sf::RenderWindow &window, sf::Color color); struct MenuItem { public: sf::IntRect buttonrect; Menu::MenuResult action; }; [/cpp] Menu.h [cpp]class Menu { public: static enum MenuResult { Exit, Options, Back, ChangeResolution, Play, Nothing }; MenuResult showMMenu(sf::RenderWindow &window); MenuResult showOMenu(sf::RenderWindow &window); private: MenuResult getMenuResponse(sf::RenderWindow &window); MenuResult handleClick(int x, int y); Menu::MenuResult Menu::handleButtonHover(sf::RenderWindow &window, Text::MenuItem menuItem, int x, int y); std::list<Text::MenuItem> menuItems; };[/cpp] How do I get MenuResult to be able to use the function highlightRectOutline()?[/QUOTE] please i have no idea how to fix this
[QUOTE=Meatpuppet;39443150]please i have no idea how to fix this[/QUOTE] Write a parent class that both of those classes inherit from, then put all common class features in that, then you'll be able to call it on any object that inherits that class. This is also how you cut down on problems like duplicated code. Edit: Nvm I'm stupid. I'll take a second look.
I also meant MenuItem, not result. I just want the struct to have access to it.
Is there a specific reason you're writing it like this, it would probably be simpler to write a class for a menu item, a class for a menu. Then inside the menu class have a list that takes an pair of a menuitem and a function pointer? Someone might have a cleaner solution to having different logic that you don't need to write multiple classes for (like play, options, exit, etc.)
MenuItem is a subclass of Text. So, basically, a menuitem is going to be text. [editline]2nd February 2013[/editline] That sounds logical to me
I love programming projects for myself, my problem is just that I can't come up with any. Any tips on how to get inspiration?
[QUOTE=ArgvCompany;39446776]I love programming project for myself, my problem is just that I can't come up with any. Any tips on how to get inspiration?[/QUOTE] You could try [url]http://projecteuler.net/[/url] if you just want to program a bunch and practice.
[QUOTE=ief014;39446788]You could try [url]http://projecteuler.net/[/url] if you just want to program a bunch and practice.[/QUOTE] I've already solved [b]a lot[/b] of those. The thing is, I want to get experience making "products" like games, applications and web stuff. Both for the experience and for feeling good that I've actually made something.
[url]http://www.squidi.net/three/index.php[/url] have a quick browse? :v:
Is there a way to scan(with java Scanner) randomly long sequence of real(double) numbers and insert them in an array
What do you mean? You have a "sequence" (string?) with doubles, and want to put them in an array? Do you have an example?
[QUOTE=Gulen;39448862]What do you mean? You have a "sequence" (string?) with doubles, and want to put them in an array? Do you have an example?[/QUOTE] this is the sequence of doubles for example: 3.0 9.0 -2.5 4.0 6.0 Now i want to put this in array, because my program must calculate an average of these number, plus, it has to outprint the number that is the farthest from the average
Ok, then. What do you know about these numbers? Will they always have that space there, and will they always have only one decimal?
[QUOTE=Gulen;39448956]Ok, then. What do you know about these numbers? Will they always have that space there, and will they always have only one decimal?[/QUOTE] The instruction didn't really specify, but i think so... Always the space between the doubles and only one decimal. I hope it isn't to complicated
Well, then you can just look for the spaces, take them out, convert to double and put into an array. [cpp]String input = "3.0 9.0 -2.5 4.0 6.0"; String tmp[] = input.split(" "); // Split by the spaces Double output[]; for(int i = 0; i < tmp.length; i++){ output[i] = Double.parseDouble(tmp[i]); } [/cpp]
[QUOTE=RandomDexter;39448929]this is the sequence of doubles for example: 3.0 9.0 -2.5 4.0 6.0 Now i want to put this in array, because my program must calculate an average of these number, plus, it has to outprint the number that is the farthest from the average[/QUOTE] But you don't know how many numbers your input will be (I assume this is what you mean by randomly long sequence)? Then when does your program stop taking input, and start doing the math? For example, you could request how many numbers the user will put in, before the user is asked to input the numbers themselves, this way you can stop asking for input when you reach the amount the user has said he would put in.
How do I set these picture to be the background of the application (when I click a button)? [IMG]http://f2.braxupload.se/eyc4ck.bf1a9abbd0.png[/IMG] [editline]2nd February 2013[/editline] (C# by the way)
Sorry, you need to Log In to post a reply to this thread.