站内搜索

搜索

手游源码-游戏源码-棋牌源码资源网-亲测源码-游戏搭建-破解游戏-网站源码-qq技术

100金币/天 购买
100金币/天 购买
100金币/天 购买

一个实时获取股票数据的app应用程序源码分享(图)

15

主题

17

帖子

423

金币

黄钻会员

Rank: 4

积分
709
发表于 2022-1-9 00:10:49 | 显示全部楼层 |阅读模式
实时获取股票数据的app源码分享 更新时间:2015 年 9 月 20 日 09:23:47 作者: 在这篇文章中,我们分享了一个实时获取股票数据的应用程序的源代码,可以用于学习。本文发布了一些重要的代码。有需要的朋友可以参考以下文章。 最近学的是应用开发,不知道写什么程序来练手。正好最近股票很火天外神坛,所以我就用一个app实时获取股票数据并命名。使用开发工具需要从官网下载,下载地址:. 不幸的是,它是公司的,任何与公司相关的东西都不能在中国直接访问,只能通过VPN。 下图是打开项目的截图: 下面描述的实施步骤是逐步的。 1.以下是.xml的内容。上排三个如何获取手机app源代码如何获取手机app源代码,分别用于显示上证综指、深成指、创业板指数。中间一行是一加一加库存。下面是一个显示添加股票列表的表格。

    

  
    
      
      
      
    
    
      
      
      
    
    
      
      
      
    
  
  
    
    

该应用程序的屏幕截图如下:
2.数据获取,这里使用新浪提供的接口实时获取股票数据,代码如下:

    
public void querySinaStocks(String list){
    // Instantiate the RequestQueue.
    RequestQueue queue = Volley.newRequestQueue(this);
    String url ="http://hq.sinajs.cn/list=" + list;
    //http://hq.sinajs.cn/list=sh600000,sh600536
    // Request a string response from the provided URL.
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
        new Response.Listener() {
          @Override
          public void onResponse(String response) {
            updateStockListView(sinaResponseToStocks(response));
          }
        },
        new Response.ErrorListener() {
          @Override
          public void onErrorResponse(VolleyError error) {
          }
        });
    queue.add(stringRequest);
  }

它用于在这里发送 Http 请求。它需要在 build.: 'com..::1.0.19' 中添加。 3.定时刷新股票数据,使用Timer,每两秒发送请求获取数据,代码如下:

    
  Timer timer = new Timer("RefreshStocks");
    timer.schedule(new TimerTask() {
      @Override
      public void run() {
        refreshStocks();
      }
    }, 0, 2000);
  private void refreshStocks(){
    String ids = "";
    for (String id : StockIds_){
      ids += id;
      ids += ",";
    }
    querySinaStocks(ids);
  }

4.程序退出时存储股票代码,下次打开应用时,可以显示最后的股票列表。代码显示如下。

    
 private void saveStocksToPreferences(){
    String ids = "";
    for (String id : StockIds_){
      ids += id;
      ids += ",";
    }
    SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putString(StockIdsKey_, ids);
    editor.commit();
  }
  @Override
  public void onDestroy() {
    super.onDestroy(); // Always call the superclass
    saveStocksToPreferences();
  }

5.删除选中的股票并在 .xml 中添加一个。

    

  
  

代码响应事件并删除:

    
 @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
      return true;
    }
    else if(id == R.id.action_delete){
      if(SelectedStockItems_.isEmpty())
        return true;
      for (String selectedId : SelectedStockItems_){
        StockIds_.remove(selectedId);
        TableLayout table = (TableLayout)findViewById(R.id.stock_table);
        int count = table.getChildCount();
        for (int i = 1; i < count; i++){
          TableRow row = (TableRow)table.getChildAt(i);
          LinearLayout nameId = (LinearLayout)row.getChildAt(0);
          TextView idText = (TextView)nameId.getChildAt(1);
          if(idText != null && idText.getText().toString() == selectedId){
            table.removeView(row);
            break;
          }
        }
      }
      SelectedStockItems_.clear();
    }
    return super.onOptionsItemSelected(item);
  }

截图:
6.当有大量挂单时,发送消息提醒,代码如下:

    
{
...
      String text = "";
      String sBuy = getResources().getString(R.string.stock_buy);
      String sSell = getResources().getString(R.string.stock_sell);
      if(Double.parseDouble(stock.b1_ )>= StockLargeTrade_) {
        text += sBuy + "1:" + stock.b1_ + ",";
      }
      if(Double.parseDouble(stock.b2_ )>= StockLargeTrade_) {
        text += sBuy + "2:" + stock.b2_ + ",";
      }
      if(Double.parseDouble(stock.b3_ )>= StockLargeTrade_) {
        text += sBuy + "3:" + stock.b3_ + ",";
      }
      if(Double.parseDouble(stock.b4_ )>= StockLargeTrade_) {
        text += sBuy + "4:" + stock.b4_ + ",";
      }
      if(Double.parseDouble(stock.b5_ )>= StockLargeTrade_) {
        text += sBuy + "5:" + stock.b5_ + ",";
      }
      if(Double.parseDouble(stock.s1_ )>= StockLargeTrade_) {
        text += sSell + "1:" + stock.s1_ + ",";
      }
      if(Double.parseDouble(stock.s2_ )>= StockLargeTrade_) {
        text += sSell + "2:" + stock.s2_ + ",";
      }
      if(Double.parseDouble(stock.s3_ )>= StockLargeTrade_) {
        text += sSell + "3:" + stock.s3_ + ",";
      }
      if(Double.parseDouble(stock.s4_ )>= StockLargeTrade_) {
        text += sSell + "4:" + stock.s4_ + ",";
      }
      if(Double.parseDouble(stock.s5_ )>= StockLargeTrade_) {
        text += sSell + "5:" + stock.s5_ + ",";
      }
      if(text.length() > 0)
        sendNotifation(Integer.parseInt(sid), stock.name_, text);
...
}
  public void sendNotifation(int id, String title, String text){
    NotificationCompat.Builder nBuilder =
        new NotificationCompat.Builder(this);
    nBuilder.setSmallIcon(R.drawable.ic_launcher);
    nBuilder.setContentTitle(title);
    nBuilder.setContentText(text);
    nBuilder.setVibrate(new long[]{100, 100, 100});
    nBuilder.setLights(Color.RED, 1000, 1000);
    NotificationManager notifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notifyMgr.notify(id, nBuilder.build());
  }

截图:
以上分享了一款通过图文实时获取股票数据的app源码。我希望你喜欢它。
【天外神坛】免责声明及帮助
1.重要:如果遇到隐藏内容回复后显示为代码状态,直接刷新一下页面即可解决此问题。
2.本文部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责。
3.若您需要商业运营或用于其他商业活动,请您购买正版授权并合法使用。
4.如果本站有侵犯、不妥之处的资源,请在网站右边客服联系我们。将会第一时间解决!
5.本站所有内容均由互联网收集整理、网友上传,仅供大家参考、学习,不存在任何商业目的与商业用途。
6.本站提供的所有资源仅供参考学习使用,版权归原著所有,禁止下载本站资源参与商业和非法行为,请在24小时之内自行删除!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

老群被封加此新群不迷路。
上个主题 下个主题 快速回复 返回列表 客服中心 搜索 QQ加群
上个主题 下个主题 快速回复 返回列表 客服中心 搜索 QQ加群

QQ|Archiver|小黑屋|天外神坛

湘ICP备2021015333号

Powered by 天外神坛 X3.4 © 2020-2022 天外神坛