Faced a difficult practice in the development of a simple simulation game. The game has 4 screens with different lists of actions. For transitions between them I use ViewFlipper
, for the list - ListView
. The game has 7 indicators (money, experience, etc.). Each action in the game depends on these indicators and entails an increase / decrease. Moreover, different actions bring different effects (for example, “going to work” brings the effect of reducing vigor, but increasing money, while “buying food” - reducing money, but increasing satiety, etc.). Each action is performed by clicking on a specific item ( ListView
item). Each item has an action text and its effects. Since, all the effects are different, and it’s not logical to make your markup for everyone, you’ll have to fill it with static data. But moreover, the filling itself will depend on other data, ie it will be dynamic. Let's look at the example of a single ListView
:
item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/item_selector" android:gravity="left"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="GO" android:textColor="#FFFFFF" android:textSize="20sp" android:id="@+id/name_item" android:gravity="left" android:layout_margin="10dp" android:textStyle="bold"/> <LinearLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:orientation="horizontal" android:gravity="right" android:weightSum="7"> <TextView android:layout_height="25dp" android:layout_width="wrap_content" android:text="+15" android:textColor="#F95D1C" android:textSize="19sp" android:id="@+id/vdohnovenie" android:textStyle="bold" android:gravity="center"/> <TextView android:layout_height="25dp" android:layout_width="wrap_content" android:text="+15" android:textColor="#FFA000" android:textSize="19sp" android:id="@+id/popular" android:textStyle="bold" android:gravity="center"/> <TextView android:layout_height="25dp" android:layout_width="wrap_content" android:text="+15" android:textColor="#F0FF00" android:textSize="19sp" android:id="@+id/money" android:textStyle="bold" android:gravity="center"/> <TextView android:layout_height="25dp" android:layout_width="wrap_content" android:text="+15" android:textColor="#00FF00" android:textSize="19sp" android:id="@+id/guitar" android:textStyle="bold" android:gravity="center"/> <TextView android:layout_height="25dp" android:layout_width="wrap_content" android:text="+15" android:textColor="#00AAFF" android:textSize="19sp" android:id="@+id/vokal" android:textStyle="bold" android:gravity="center"/> <TextView android:layout_height="25dp" android:layout_width="wrap_content" android:text="+15" android:textColor="#5F7FD0" android:textSize="19sp" android:id="@+id/harizma" android:textStyle="bold" android:gravity="center"/> <TextView android:layout_height="25dp" android:layout_width="wrap_content" android:text="+15" android:textColor="#AE51C7" android:textSize="19sp" android:id="@+id/style" android:textStyle="bold" android:gravity="center"/> </LinearLayout> </LinearLayout>
A piece of code from java
String[] summary_lv2 = {"Слушать радио", "Выпить пива", "Общаться с крутыми музыкантами", "Выпить пива с музыкантами", "Слушать комп", "Слушать винил", "Концерт местной группы", "Концерт отечественной группы", "Концерт зарубежной группы"}; String[] secondary_vdxnvn_lv2 = {"5", "15", "10", "15", "10", "15", "30", "50", "80"}; String[] secondary_popular_lv2 = {"", "", "", "", "", "", "", "", ""}; String[] secondary_money_lv2 = {"", "-60", "", "-120", "", "", "-400", "-600", "-1000"}; String[] secondary_guitar_lv2 = {"", "", "", "", "", "", "", "", ""}; String[] secondary_vokal_lv2 = {"", "", "", "", "", "", "", "", ""}; String[] secondary_harizma_lv2 = {"", "", "", "", "", "", "", "1", "1"}; String[] secondary_style_lv2 = {"", "", "", "", "", "", "", "", "1"}; String[] from = {"name_item", "vdoxnovenie", "popular", "money", "guitar", "vokal", "harizma", "style"}; int[] to = {R.id.name_item, R.id.vdohnovenie, R.id.popular, R.id.money, R.id.guitar, R.id.vokal, R.id.harizma, R.id.style}; ArrayList<HashMap<String, String>> arrayList = new ArrayList<HashMap<String, String>>(); HashMap<String, String> hashmap; for(int i = 0; i < summary_lv2.length; i++){ hashmap = new HashMap<String, String>(); hashmap.put("name_item", "" + summary_lv2[i]); hashmap.put("vdoxnovenie", "+" + secondary_vdxnvn_lv2[i]); hashmap.put("popular", "" + secondary_popular_lv2[i]); hashmap.put("money", "" + secondary_money_lv2[i]); hashmap.put("guitar", "" + secondary_guitar_lv2[i]); hashmap.put("vokal", "" + secondary_vokal_lv2[i]); hashmap.put("harizma", "" + secondary_harizma_lv2[i]); hashmap.put("style", "" + secondary_style_lv2[i]); arrayList.add(hashmap); } SimpleAdapter adapter = new SimpleAdapter(this, arrayList, R.layout.item, from, to); lv1.setAdapter(adapter);
For example, when there is no effect associated with money, I give empty quotes and thus the effect is not shown. Thus, only useful information will be located in the effects (inspiration +0, etc. will not be, such data show no sense).
And now the questions :
1) The player must understand what an effect is doing, what indicator it changes, so you need to add an icon (coin, inspiration, etc.) to the TextView
but when you don’t need to show the effect, you’ll pass little to TextView
empty quotes, as the icon will remain in place. How to force it also not to be shown in case the text is empty?
2) If empty quotes are passed to the TextView
, the view
element is not shown and its "place" is also shown. As a result, those TextView
to which values other than null
are transmitted are shown one after another, horizontally, as if there are no TextView
to which nothing is transmitted at all. Well, that's what I need. But the fact is that they are pressed together. And if they all assign an attribute of the layout_marginRight
type? Of course, indents appear, they are divided, but in the case of the transfer of empty quotes, TextView
text, of course, does not display, but takes place. As a result, in their place there are gaps, which looks very ugly. So, how to make sure that there were no padding and no space from the "empty" TextView
. Please do not offer something like "pass the number and spaces into the TextView
. I then need to make a listener who will take these numbers. And once again, slowing down the game by cutting numbers from spaces is not good. I’m waiting for good advice from experienced developers. I’m suffering already a week. Thanks in advance :)
How can I solve the problem with the adapter? Give a link where to dig
SimpleCursorAdapter
in view-elements. For this check, the transmitted value must be caught in the custom adapter, which I do not want to do . I strive to minimize the code. It would be so simple, I would not ask a question :)))) - Flippy