安卓版超级简单上下左右滚动Listview,仿同花顺自选列表

主流股票行情列表显示,ScrollView+HorizontalScrollView+listview 联动

(截图弄的不是很好)

 

代码使用示例

package com.example.stockmarket;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import com.example.stockmarket.adapter.LeftAdapter;
import com.example.stockmarket.adapter.RightAdapter;
import com.example.stockmarket.entity.Product;
import com.example.stockmarket.view.MyListView;
import com.example.stockmarket.view.MySyncHorizontalScrollView;

import java.util.ArrayList;
import java.util.List;

public class MyActivity extends Activity {
    MySyncHorizontalScrollView rightTitleHorscrollView = null, rightContentHorscrollView = null;
    MyListView contentListViewLeft = null, contentListViewRight = null;
    LeftAdapter leftAdapter = null;
    RightAdapter rightAdapter = null;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //initviews
        rightTitleHorscrollView = (MySyncHorizontalScrollView)findViewById(R.id.rightTitleHorscrollView);
        rightContentHorscrollView = (MySyncHorizontalScrollView)findViewById(R.id.rightContentHorscrollView);
        contentListViewLeft = (MyListView)findViewById(R.id.contentListViewLeft);
        contentListViewRight = (MyListView)findViewById(R.id.contentListViewRight);

        //相互引用
        rightTitleHorscrollView.setmSyncView(rightContentHorscrollView);
        rightContentHorscrollView.setmSyncView(rightTitleHorscrollView);

        //setadapter
        leftAdapter = new LeftAdapter(this, 0, new ArrayList());
        contentListViewLeft.setAdapter(leftAdapter);
        rightAdapter = new RightAdapter(this, 0, new ArrayList());
        contentListViewRight.setAdapter(rightAdapter);

        //get data
        new Thread(){
            @Override
            public void run() {
                super.run();

                List productList = DataUtil.getData(MyActivity.this);
                Message message = handler.obtainMessage();
                message.what = 0;
                message.obj = productList;
                message.sendToTarget();
            }
        }.start();
    }

    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    for (Product product : (ArrayList)msg.obj) {
                        leftAdapter.add(product);

                        rightAdapter.add(product);
                    }

                    break;
            }

        }
    };
}

 

GitHub 地址:https://github.com/lovemelovemydog/StockMarket/

 

本地下载

 

分享到:

评论已关闭