避免在ListView的两列中跳转

时间:2014-05-02 17:16:32

标签: java android-listview android-arrayadapter

我根据team_id(得分表)安排了两列listview排列数据,任何想法如何避免某些项目之间的差距?

2 col listview

这是我的inflater

    @Override
    public View getAmazingView(int position, View convertView, ViewGroup parent) {
        View res = convertView;

        if (res == null) res = getLayoutInflater().inflate(R.layout.calendario_item_composer, null);

        TextView team_nombre = (TextView) res.findViewById(R.id.team_nombre);
        TextView player_name1 = (TextView) res.findViewById(R.id.player_name1);
        TextView player_name2 = (TextView) res.findViewById(R.id.player_name2);
        TextView stats_minute1 = (TextView) res.findViewById(R.id.stats_minute1);
        TextView stats_minute2 = (TextView) res.findViewById(R.id.stats_minute2);

        Detailbystats detailbystats = getItem(position);

                    // get the first team_id, to be able to categorize later 
        if(position==0){
            Globals.team_id = detailbystats.team_id;
        }

        // if is team 1 goes to 1st column, else goes to 2nd column
        if(Globals.team_id.equals(detailbystats.team_id)){
            player_name1.setText(detailbystats.player_name);
            stats_minute1.setText(detailbystats.stats_minute);
        }
        else{
            player_name2.setText(detailbystats.player_name);
            stats_minute2.setText(detailbystats.stats_minute);
        }

        return res;
    }

这是我的布局

<?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="fill_parent"
    android:orientation="vertical"
    android:background="#404042" >

    <include
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/calendario_item_composer_header" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/list_selector_noticias"
        android:orientation="horizontal" >

        <!-- Header Categoria -->
        <TextView
            android:id="@+id/stats_cat_title"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:visibility="gone" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="left"
                android:orientation="horizontal" >

                <!-- Player Name -->
                <TextView
                    android:id="@+id/player_name1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="1dip"
                    android:textColor="#dddddd"
                    android:textSize="11sp"
                    android:paddingTop="5dip"
                    android:paddingBottom="5dip"
                    android:paddingLeft="5dip" />

                <!-- Player Goal -->
                <TextView
                    android:id="@+id/stats_minute1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="1dip"
                    android:textColor="#dddddd"
                    android:textSize="11sp"
                    android:paddingTop="5dip"
                    android:paddingBottom="5dip" />
            </LinearLayout>

            <View
                android:layout_width="1dp"
                android:layout_height="fill_parent"
                android:background="#b0b0b2"/>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="right"
                android:orientation="horizontal" >

                <!-- Player Name -->
                <TextView
                    android:id="@+id/player_name2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="1dip"
                    android:textColor="#dddddd"
                    android:textSize="11sp"
                    android:paddingTop="5dip"
                    android:paddingBottom="5dip"
                    android:paddingRight="5dip" />

                <!-- Player Goal -->
                <TextView
                    android:id="@+id/stats_minute2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="1dip"
                    android:textColor="#dddddd"
                    android:textSize="11sp"
                    android:paddingTop="5dip"
                    android:paddingBottom="5dip" />
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>

</LinearLayout>

这是我的JSON来填充适配器

{
"game_details": [
    {
        "game_id": "23",
        "team_id": "20",
        "team_nombre": "Mictlán",
        "stats_cat_id": "2",
        "stats_cat_title": "Goles",
        "player_name": "Guillermo Alvarez",
        "stats_value": "",
        "stats_minute": "3",
        "stats_comment": ""
    },
    {
        "game_id": "23",
        "team_id": "20",
        "team_nombre": "Mictlán",
        "stats_cat_id": "3",
        "stats_cat_title": "Tarjetas Amarillas",
        "player_name": "Jose Gracias",
        "stats_value": "",
        "stats_minute": "30",
        "stats_comment": ""
    },
    {
        "game_id": "23",
        "team_id": "20",
        "team_nombre": "Mictlán",
        "stats_cat_id": "3",
        "stats_cat_title": "Tarjetas Amarillas",
        "player_name": "Edgar Cotto",
        "stats_value": "",
        "stats_minute": "24",
        "stats_comment": ""
    }
],
"stats": [
    "Goles",
    "Tarjetas Amarillas"
],
"detailbystats": [
    [
        {
            "game_id": "23",
            "team_id": "20",
            "team_nombre": "Mictlán",
            "stats_cat_id": "2",
            "stats_cat_title": "Goles",
            "player_name": "Guillermo Alvarez",
            "stats_value": "",
            "stats_minute": "3",
            "stats_comment": ""
        }
    ],
    [
        {
            "game_id": "23",
            "team_id": "20",
            "team_nombre": "Mictlán",
            "stats_cat_id": "3",
            "stats_cat_title": "Tarjetas Amarillas",
            "player_name": "Jose Gracias",
            "stats_value": "",
            "stats_minute": "30",
            "stats_comment": ""
        },
        {
            "game_id": "23",
            "team_id": "20",
            "team_nombre": "Mictlán",
            "stats_cat_id": "3",
            "stats_cat_title": "Tarjetas Amarillas",
            "player_name": "Edgar Cotto",
            "stats_value": "",
            "stats_minute": "24",
            "stats_comment": ""
        }
    ]
],
"detailsxpairs": [
    [
        [
            {
                "game_id": "23",
                "team_id": "20",
                "team_nombre": "Mictlán",
                "stats_cat_id": "2",
                "stats_cat_title": "Goles",
                "player_name": "Guillermo Alvarez",
                "stats_value": "",
                "stats_minute": "3",
                "stats_comment": ""
            }
        ]
    ],
    [
        [
            {
                "game_id": "23",
                "team_id": "20",
                "team_nombre": "Mictlán",
                "stats_cat_id": "3",
                "stats_cat_title": "Tarjetas Amarillas",
                "player_name": "Jose Gracias",
                "stats_value": "",
                "stats_minute": "30",
                "stats_comment": ""
            }
        ],
        [
            {
                "game_id": "23",
                "team_id": "20",
                "team_nombre": "Mictlán",
                "stats_cat_id": "3",
                "stats_cat_title": "Tarjetas Amarillas",
                "player_name": "Edgar Cotto",
                "stats_value": "",
                "stats_minute": "24",
                "stats_comment": ""
            }
        ]
    ]
]
}

0 个答案:

没有答案