1. 程式人生 > >Keep Learning , Keep Improving !

Keep Learning , Keep Improving !

1.aty

package com.louis.classifymenuview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import
java.util.List; import java.util.Map; public class MainActivity extends AppCompatActivity { List<Map<String,Object>> mainMapList=new ArrayList<>(); List<List<Map<String,Object>>> moreMapList_List=new ArrayList<>(); ListView moreLv; MainListBaseAdapter myBaseAdapter; MoreListBaseAdpter moreListBaseAdpter; @Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initData(); ListView mainLv= (ListView) findViewById(R.id.classify_mainlist); moreLv= (ListView) findViewById(R.id.classify_morelist); myBaseAdapter=new
MainListBaseAdapter(this,mainMapList); // mainLv.setAdapter(new SimpleAdapter(this, mainMapList, R.layout.list_items, new String[]{"mianName"}, new int[]{R.id.id_tv_list_item})); mainLv.setAdapter(myBaseAdapter); // mainLv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); initMoreBaseAdapter(0); mainLv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { myBaseAdapter.setNowSelectedIndex(position); initMoreBaseAdapter(position); } }); } private void initMoreBaseAdapter(int position) { moreListBaseAdpter=new MoreListBaseAdpter(this,moreMapList_List.get(position)); // SimpleAdapter simpleAdapter= new SimpleAdapter(MainActivity.this, moreMapList_List.get(position), R.layout.list_items, new String[]{"moreName"}, new int[]{R.id.id_tv_list_item}); moreLv.setAdapter(moreListBaseAdpter); moreLv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { moreListBaseAdpter.setNowSelectedIndex(position); } }); moreListBaseAdpter.notifyDataSetChanged(); } private void initMoreAdapter(int position) { SimpleAdapter simpleAdapter= new SimpleAdapter(MainActivity.this, moreMapList_List.get(position), R.layout.list_items, new String[]{"moreName"}, new int[]{R.id.id_tv_list_item}); moreLv.setAdapter(simpleAdapter); simpleAdapter.notifyDataSetChanged(); } private void initData() { for (int i=0;i<15;i++){ Map<String,Object> mianMap=new HashMap<>(); mianMap.put("mainName","mainName"+i); mainMapList.add(mianMap); List<Map<String,Object>> moreMapList=new ArrayList<>(); for (int j=0;j<10;j++){ Map<String,Object> moreMap=new HashMap<>(); moreMap.put("moreName","mainName"+i+"下moreName"+j); moreMapList.add(moreMap); } moreMapList_List.add(moreMapList); } } }

2.xml 4aty

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context="com.louis.classifymenuview.MainActivity">


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ListView
            android:id="@+id/classify_mainlist"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="20"
            android:background="#fff"
            android:cacheColorHint="#00000000"
            android:divider="#fff"
            android:dividerHeight="1px"
            android:fastScrollEnabled="true"
            android:listSelector="#00000000"
            android:scrollbars="none" />

        <ListView
            android:id="@+id/classify_morelist"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="17"
            android:background="#fff"
            android:cacheColorHint="#00000000"
            android:divider="#ffebebeb"
            android:dividerHeight="0.5px"
            android:fastScrollEnabled="true"
            android:listSelector="#00000000"
            android:scrollbars="none" />

    </LinearLayout>
</LinearLayout>

3.簡陋的item xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<TextView
    android:id="@+id/id_tv_list_item"
    android:layout_width="match_parent"
    android:gravity="center_vertical"
    android:padding="10dp"
    android:layout_height="match_parent" />
</LinearLayout>

4.main adpter MainListBaseAdapter

package com.louis.classifymenuview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/3/17.
 */
public class MainListBaseAdapter extends BaseAdapter {
    Context context;
    List<Map<String,Object>> mainMapList;

    public int getNowSelectedIndex() {
        return nowSelectedIndex;
    }

    public void setNowSelectedIndex(int nowSelectedIndex) {
        this.nowSelectedIndex = nowSelectedIndex;
        this.notifyDataSetChanged();//及時通知顯示
    }

    private int nowSelectedIndex = 0;
    public MainListBaseAdapter(Context context, List<Map<String, Object>> mainMapList) {
        this.context = context;
        this.mainMapList=mainMapList;
    }

    @Override
    public int getCount() {
        return mainMapList.size();
    }

    @Override
    public Object getItem(int position) {
        return mainMapList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.list_items,null);
        }
        TextView tv_list_item= (TextView) convertView.findViewById(R.id.id_tv_list_item);
        tv_list_item.setText(mainMapList.get(position).get("mainName").toString());

        if (position==nowSelectedIndex){
            tv_list_item.setBackgroundColor(0xFFFFFFFF);
        }else
        {
            tv_list_item.setBackgroundColor(0xFFEBEBEB);
        }

        return convertView;
    }
}

5。 more list adapter

package com.louis.classifymenuview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/3/17.
 */
public class MoreListBaseAdpter extends BaseAdapter {

    Context context;
    List<Map<String, Object>> moreMapList;
    private int nowSelectedIndex = 0;

    public MoreListBaseAdpter(Context context, List<Map<String, Object>> moreMapList) {
        this.context = context;
        this.moreMapList = moreMapList;
    }

    @Override
    public int getCount() {
        return moreMapList.size();
    }

    @Override
    public Object getItem(int position) {
        return moreMapList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.list_items, null);
        }
        TextView tv_list_item = (TextView) convertView.findViewById(R.id.id_tv_list_item);
        tv_list_item.setText(moreMapList.get(position).get("moreName").toString());

        if (position == nowSelectedIndex) {
            tv_list_item.setTextColor(0xFFB3EE3A);
        } else {
            tv_list_item.setTextColor(0xFF525252);
        }
        return  convertView;
    }

    public int getNowSelectedIndex() {
        return nowSelectedIndex;
    }

    public void setNowSelectedIndex(int nowSelectedIndex) {
        this.nowSelectedIndex = nowSelectedIndex;
        this.notifyDataSetChanged();//及時通知顯示
    }
}

結果

這裡寫圖片描述

相關推薦

Keep Learning , Keep Improving !

1.aty package com.louis.classifymenuview; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import and

2018-08-20再啟程--Keep Learning, Keep Coding!

文章 運維 cnblogs 一個 加油! 架構 雅思 odin 組織 說好的堅持呢 堅持果然不是誰都能做到的,更不是說說就可以事當初的熱情高漲,把自己想的太厲害了,結果證明自己不過如此! 昨天群裏推薦了一個博客園的文章,一個堅持了300多篇的大佬。我為什麽堅持寫博客共勉

2017 年度總結: Keep learning, Keep thinking

部落格地址 2017 年原本應該和去年一樣,工作日上班、下班、玩手機、睡覺,週末就跑去找同學玩(通常都是網咖打 Dota)。直到那一天,一切開始變得不一樣…… 邂逅 那是 3 月 27 號星期一,公司新來了一位女同事。在中午吃飯的時候我第一次見到她,我想我

Keep Learning】學習Spark、CarbonData 、Alluxio等,且為其Contributor,Github為:https://github.com/xubo245。歡迎微信聯絡601450868!

學習Spark、CarbonData 、Alluxio等,且為其Contributor,Github為:https://github.com/xubo245。歡迎微信聯絡601450868!...

Keep Learning(學習Spark、CarbonData 、Alluxio等,且為其Contributor,Github為:https://github.com/xubo245。歡迎微信聯絡601450868!)

學習Spark、CarbonData 、Alluxio等,且為其Contributor,Github為:https://github.com/xubo245。歡迎微信聯絡601450868!...

保持學習!Keep Learning!!!

1. 前言  歡迎學習《職業生涯規劃》中級課程。   在《職業生涯規劃》初級課程中,我們瞭解瞭如何通過對自我及社會環境的分析來選擇適合自己的職業。那麼,在確定大的職業生涯方向後,如何制定具體的職業生

Slow down, Keep learning and Enjoy life

1. 什麼是Attention機制? 其實我沒有找到attention的具體定義,但在計算機視覺的相關應用中大概可以分為兩種: 1)學習權重分佈:輸入資料或特徵圖上的不同部分對應的專注度不同,對此Jason Zhao在知乎回答中概括得很好,大體如下: -

Python3.6教程(一)--Keep Learning系列

檢視Python的版本,以及進入Python互動式程式設計模式 print('Hello World') 你可以將以上程式碼儲存在hello.py檔案中並在cmd中使用python命令執行該指令碼檔案。 python hello.py

【淺墨的遊戲程式設計Blog】毛星雲(淺墨)的專欄(Keep Reading , Keep Writing , Keep Coding.)

毛星雲,網路ID「淺墨」,90後,熱愛遊戲開發、遊戲引擎、計算機圖形、實時渲染等技術,就職於騰訊互娛。 微軟最有價值專家 著作《Windows遊戲程式設計之從零開始》、《OpenCV3程式設計入門》 碩士就讀於南京航空航天大學航天學院(2013級碩士研究生),已於2016年三月畢業。本科

【【淺墨的遊戲程式設計Blog】毛星雲(淺墨)的專欄】Keep Reading , Keep Writing , Keep Coding.

毛星雲,網路ID「淺墨」,90後,熱愛遊戲開發、遊戲引擎、計算機圖形、實時渲染等技術,就職於騰訊互娛。 微軟最有價值專家 著作《Windows遊戲程式設計之從零開始》、《OpenCV3程式設計入門》 碩士就讀於南京航空航天大學航天學院(2013級碩士研究生),已於2016年三月畢業。本科

Machine learning helps improving photonic applications

Photonic nanostructures can be used for many applications besides solar cells--for example, optical sensors for cancer markers or other biomolecules. A tea

Keep Trying, Keep Fighting

近來由於資料記錄和屬性規模的急劇增長,大資料處理平臺和並行資料分析演算法也隨之出現。於此同時,這也推動了資料降維處理的應用。實際上,資料量有時過猶不及。有時在資料分析應用中大量的資料反而會產生更壞的效能。 最新的一個例子是採用 2009 KDD Challen

Keep Awake,Keep Studying,Keep Moving,Keep...

        事情的起因是這樣的,因為需要在Email的顯示介面中為電話號碼新增高亮顯示,從而提高使用者體驗。我想用過google自帶郵箱的朋友都知道,當我們的收到郵件的內容中含有網址,郵箱地址時,會在顯示介面中以超連結的方式顯示,此時當我們點選該網址或者郵箱地址時,便會

keep hungry keep foolish

一、字元轉換函式 1、ASCII() 返回字元表示式最左端字元的ASCII 碼值。在ASCII()函式中,純數字的字串可不用‘’括起來,但含其它字元的字串必須用‘’括起來使用,否則會出錯。 2、CHAR() 將ASCII 碼轉換為字元。如果沒有輸入0 ~ 255 之間的ASCII 碼值,CHAR()

Keep Thinking And Learning

背景     最近有個簡單的需求,離線資料探勘得出的標籤需要支援online的查詢,查詢場景比較簡單,支援按照單個id或者多個id批量查詢,tp99需要在200ms,批量的時候id 集合的大小不會超過1000,平均下來不會超過200的樣子。這種場景直接上ES相對來說比較省事

Machine Learning will keep Sydney Harbour bridge safe

Sydney Harbour Bridge weighs 52,800 tonnes and it is the first iconic structure which we see, lit up with fireworks on NY Eve/Day. At 134 metres,she is the

BNUOJ 52511 Keep In Line

class blog ring break 需要 main code bre 是否 隊列,$map$。 每次出隊進行出隊操作的是時候,先把隊列中需要出隊的人全部出隊,然後比較對頭和當前出隊的人是否相同。 #include<bits/stdc++.h>

HTTP/1.0+ "keep-alive" 連接

通過 保持 就會 無法 首部 報文 response line -a 一、keep-alive 連接 (1) 我們在使用串行連接的時候,比如加載四張圖片,當加載第一張圖片時,會建立連接,加載完後會關閉連接,加載第二張圖片時同樣會先建立連接再關閉連接,以此類推,這樣就會消耗

Uva 1153 Keep the Customer Satisfied (貪心+優先隊列)

最長 題意 code log algo cmp cst name node 題意:已知有n個工作,已知每個工作需要的工作時間qi和截至時間di,工作只能串行完成,問最多能完成多少個工作 思路:首先我們按照截至時間從小到大排序,讓它們依次進入優先隊列中,當發生執行完成時間大於

HTTP協議頭部與Keep-Alive模式詳解

兩個 conn exp uid iteye 想象 ket -c ack 1、什麽是Keep-Alive模式? 我們知道HTTP協議采用“請求-應答”模式,當使用普通模式,即非KeepAlive模式時,每個請求/應答客戶和服務器都要新建一個連接,完成