У меня есть ListView в действии MyBets. XML-формат ниже:Заполнение ListView с пользовательским desjgn с использованием HashMap
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background = "@color/grey05"
tools:context="com.example.betterapp.MyBets">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<!-- Main ListView
Always give id value as list(@android:id/list)
-->
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:background = "@color/betcolor"
android:layout_height="wrap_content"
></ListView>
</LinearLayout>
</RelativeLayout>
У меня также есть пользовательский макет для этого ListView в активности SingleBet. XML Layout Ниже:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="#49DE56"
android:orientation="horizontal" >
<TextView
android:id="@+id/namesofteams"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_weight="1.3"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Sevilla vs Barcelona"
android:textStyle="bold" />
<TextView
android:id="@+id/selection"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="40dp"
android:layout_weight="7"
android:layout_height="wrap_content"
android:textColor= "#585E5E"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Sevilla 3.55"
android:textStyle="italic" />
<TextView
android:id="@+id/statusofbet"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_weight="3"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Open"
android:textStyle="bold" />
</LinearLayout>
Обычай макет должен выглядеть следующим образом:
Teams Selection Status
A-B A @ 2.3 Open
Я использовал следующий код для получения команд и переменных выбора, которые я хотел бы добавить.
HashMap<Integer,Game> hashmapofgames = new HashMap<Integer, Game>();
HashMap<Integer, Game> listofgames;
listofgames = newBet.getlistofgames();
for (Integer x : listofgames.keySet()) {
TextView teams = (TextView) findViewById(R.id.textView2);
String getTeams = listofgames.get(x).getTeams();
teams.setText(getTeams);
TextView selectionodds = (TextView) findViewById(R.id.textView3);
String selectedoutcome = listofgames.get(x).getSelection();
Double selectedoutcomeodds = listofgames.get(x).getSelectedOdds();
String selectedteam = "";
if (selectedoutcome == "home") {
selectedteam = getTeams.substring(0, getTeams.lastIndexOf("-"));
} else if (selectedoutcome == "draw") {
selectedteam = "Draw";
} else if (selectedoutcome == "away") {
selectedteam = getTeams.substring(getTeams.lastIndexOf("- ")+1,getTeams.length());
}
String selection = (selectedteam + " @" + selectedoutcomeodds);
Log.d("teams",getTeams);
Log.d("selected odds",Double.toString(selectedoutcomeodds));
Log.d("selected team", selectedteam);
Log.d("selected outcome", selectedoutcome);
Log.d("selection", selection);
Это прекрасно работает как выход из журнала показывает:
29523-29523/com.example.betterapp D/teams﹕ Villareal - Valencia
29523-29523/com.example.betterapp D/selected odds﹕ 2.5
29523-29523/com.example.betterapp D/selected team﹕ Valencia
29523-29523/com.example.betterapp D/selected outcome﹕ away
29523-29523/com.example.betterapp D/selection﹕ Valencia @2.5
Мой вопрос, как я могу заполнить ListView, так что namesofteams и выбор отображения команд и выбора. Я вызываю этот метод из отдельного класса AllGameslist.
Не могли бы вы написать короткий код, чтобы продемонстрировать, как я это сделаю. – Alk