AKMafia001's Profile User Rating: -----

Reputation: 210 Stalwart
Group:
Active Members
Active Posts:
684 (0.5 per day)
Joined:
11-June 11
Profile Views:
6,059
Last Active:
User is offline Yesterday, 12:30 PM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   AKMafia001 has not set their status

Posts I've Made

  1. In Topic: Changing Image during runtime

    Posted 3 Mar 2015

    Well! You can make an array, or maybe a Map, say, Map<String, boolean> mTexturesStatus; and iterate through it using a loop and store each value in the preferences. If a purchase is made, you can just update that preference since you will have the key.

    Later on, you would easily retrieve all or a single preferences and make decision based on its value.

    As for the logic, as you said above, I assume that you are setting the preferences when the button is clicked. So, when you program starts (say the first run) and the button is not yet clicked, then you wouldn't have saved any preferences as of yet. In that case, if you call to get the preferences they won't exit by then, and you will get a default value. The default value is, public abstract boolean getBoolean (String key, boolean defValue) what you provide in the method, for getBoolean() you provide a default value of type boolean, for getString() you provide a default value of type String and so on. So if you call, prefs.getBoolean("texturePlayer", false); and it didn't existed, you can safely get false in return and perform your decision.
  2. In Topic: Is it possible to create buttons only without using XML?

    Posted 3 Mar 2015

    The LinearLayout was in case if you had a XML layout file and you want to add views to it. Otherwise you can create the whole layout programmatically and add it to a new LinearLayout and then set the Activity's content view to that programmatically generated layout.

    Let me share an example with you, this was a project I worked on in which the layout was created from the contents of SQLite db... Below is the code,

    Note: I have simplified the code.
    LinearLayout llMain = (LinearLayout) findViewById(R.id.llMain);
    ArrayList<EditText> etInterface = new ArrayList<EditText>();
    		
    	LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    		
    
    	LinearLayout.LayoutParams tvLayoutParams = new LinearLayout.LayoutParams(
    				LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    
    	tvLayoutParams.setMargins(0, 20, 0, 0);
    		
    	if(c.moveToFirst()) {
    		
    		do {
    			TextView tvField = new TextView(this);
    			tvField.setText(c.getString(3));    // c is the cursor
    			tvField.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_Medium);
    			tvField.setTextColor(Color.BLACK);
    							
    			EditText etField = new EditText(this);
    			etField.setBackgroundResource(R.drawable.a2z_edit_text_holo_light);
    								
    			llMain.addView(tvField, tvLayoutParams);
    			llMain.addView(etField);
    				
    			etInterface.add(etField);
    		} while(c.moveToNext());
    	}
    
    


    and the simplified layout for this scenario:
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        	android:id="@+id/llMain"
        	android:layout_width="match_parent"
        	android:layout_height="wrap_content"
        	android:orientation="vertical" >
    	</LinearLayout>
    
    


    This will create a layout with TextViews and EditTexts, a TextView following a EditText following another TextView and so on!
  3. In Topic: Changing Image during runtime

    Posted 2 Mar 2015

    Since you are working in a larger project, I can't tell exactly what is it that you need.

    But, if a purchase is made, and you want to replace one texture with another, I would do it as:

    - Save a boolean in preferences and read it to see if it is true, then load the appropriate texture.

    You can just put the check in the beginning also, then on the first run, the preferences won't exit so you will get a default value indicating that no purchase was made so you can set that texture, and if it existed and had a value of true, you can load a different texture...
  4. In Topic: Changing Image during runtime

    Posted 2 Mar 2015

    You have saved your data into a preferences, but did you read them back when loading a texture?

    Read this for a quick overview!
  5. In Topic: Changing Image during runtime

    Posted 2 Mar 2015

    Hi, welcome to DIC!

    When the event occurs (purchase as you said) do you wish to permanently change the image so when then user opens the app in future the new image will show up instead of the old? And does that happens, or doesn't works that way yet?

    When you move inside your app and start activities, the current activities are added to the activity stack, and the new activity is loaded. And when you press the back button (default flow) the previous activity which is on the top of the stack is loaded and it follows the activity life cycle through resume() and so on. In that case, your code runs the normal flow and most probably will see the initial layout since the event that made changes weren't saved.

    So, either you should save the activity state in onSaveInstanceState() and when your activity is loaded again, you should restore the activity state from the bundle. This way you can know which image to load.

    Alternatively you can use SharedPreferences to save a flag or the resource name and load it when your app starts.

    Hope it makes sense!

My Information

Member Title:
</code.in.dream>
Age:
24 years old
Birthday:
January 2, 1991
Gender:
Interests:
Computers, Programming, Games, Sports, Cooking, Swimming
Full Name:
Mafia
Years Programming:
7
Programming Languages:
BASIC
C/C++
SQL
Assembly (80x86)
Java
PHP
Javascript
C#

Contact Information

E-mail:
Private

Comments

Page 1 of 1
  1. Photo

    vaseeprasanna Icon

    18 Dec 2012 - 08:29
    and your rocking
  2. Photo

    vaseeprasanna Icon

    18 Dec 2012 - 08:28
    how to make glass form in c#
  3. Photo

    AKMafia001 Icon

    09 Dec 2012 - 12:04
    You are outstanding, buddy! ;) You have to accept that... :P
  4. Photo

    Xupicor Icon

    09 Dec 2012 - 10:24
    I think you're way overstating my input here at DIC. But still, thanks. :P
  5. Photo

    raghav.naganathan Icon

    09 Dec 2012 - 09:26
    Well, thank you...:)...although its not such a good job compared to what you are doing...:)
  6. Photo

    AKMafia001 Icon

    07 Dec 2012 - 03:15
    Thanks Raghav! You are also doing good job in C/C++...
  7. Photo

    raghav.naganathan Icon

    07 Dec 2012 - 02:56
    Congrats on the excellent answer...and a well deserved 100 :)
  8. Photo

    raghav.naganathan Icon

    05 Dec 2012 - 10:29
    Dude...I have to say this...Outstanding work in the C/C++ forums...:)
    Looks like you are up in line for the expert badge :)
  9. Photo

    techdreamer Icon

    04 Nov 2012 - 06:59
    ok
Page 1 of 1