Question

I'm new to android development and I was just wondering how I should store the money value the player current has? Should i store it as a string in string.xml or should i make it an int in a method? Also how should i make the deck of cards. Should i use an array? I was told you shouldnt store it as a string and i dont know how you can display it when you launch the app if its not stored as a string. Any help would be greatly appreciated!

  <TextView
        android:background ="@android:color/white"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/cash"
        android:padding="5dip"
        /> 
 Im currently storing it in a textview
Was it helpful?

Solution

Not sure on the deck of cards, but store the money as a float. It is not an int. displaying it is simple as since java can make a float a string by simply adding the float to an empty string

str = "" + flt; complicated? How?

protected boolean store_cash(){
   SharedPreferences settings = getSharedPreferences("GENERAL", 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putFloat("cash", mCash);
        return editor.commit();
}
protected void load_cash(){
 SharedPreferences settings = getSharedPreferences("GENERAL", 0);
 mCash = settings.getFloat("cash", (float) 0.0);
}

with that it's just a matter of setting the title of the textview

protected void display_cash(){
    TextView cash = (TextView ) findViewById(R.id.cash);
    cash.setText( "$" + mCash);  //formatting may be required..  google is your friend
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top