android 控件AutoCompleteTextView实战

首先自定义一个AutoCompleteTextView,目的就是为了解决在一开始没有输入任何字符的时候提示整个列表

public class MyAutoCompleteTextView extends AutoCompleteTextView {

    public MyAutoCompleteTextView(Context context) {
        super(context);
    }

    public MyAutoCompleteTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean enoughToFilter() {
        return true;
    }
}

在layout里定义自定义的AutoCompleteTextView

<com.dukelight.testandroidm.MyAutoCompleteTextView
    android:id="@+id/act_main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:completionThreshold="1"
    android:dropDownHorizontalOffset="10dp"
    android:text="" >

    <requestFocus />
</com.dukelight.testandroidm.MyAutoCompleteTextView>

最后就是Activity里的调用代码

public class TestAutoCompleteActivity extends Activity {


    String[] place = new String[]{"白云", "广州", "五山", "天河", "越秀", "二电厂", "大学城", "中山"};
    @InjectView(R.id.act_main)
    MyAutoCompleteTextView mActMain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_test_complete);
        ButterKnife.inject(this);

        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, place);
        mActMain.setAdapter(arrayAdapter);

        mActMain.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // 手动向下弹出匹配的菜单        
                mActMain.showDropDown(); 
                return false;
            }
        });
    }
}

最后的最后放上效果图片

空字符串显示全部 匹配字符串显示

使用hexo搭建博客平台,记录过程

1. 在github上创建一个Repository,名字为xx.github.io

Repository 的地址就是 http://www.github.com/id/id.github.io.git

2. 配置ssh keys

打开github网站,然后找到ssh keys的设置地方,具体网站上有教程。设置完测试一下

ssh -T git@github.com

3. 安装hexo

npm install -g hexo

新建一个文件夹来保存
hexo init
npm install

安装好后,就可以开始了
hexo generate //可以简写为 hexo g
hexo server //可以简写为 hexo s

在浏览器中输入 localhost:4000 查看本地博客

4. 部署到github上去

npm install hexo-deployer-git --save

打开hexo文件夹的_config.yml ,文件拉到最后,设置deploy的type为git,repository为:https://github.com/id/id.github.io.git(注意:必须在type和repo后面加上一个空格)

hexo g
hexo deploy    //可简写为 hexo d

5. 开始用hexo写文章

hexo博客目录里的source/_posts就是放文章的(使用markdown语法编写),格式是xx.md

hexo new post "first article"   

会创建一个叫first article.md的文件(使用markdown语法),使用macdown打开找个文件,然后就可以开始写文章,写完后打命令

hexo g
hexo s
hexo d

6. 关于文章中的图片问题

使用七牛云存储来保存图片,并换取图片外链. (http://www.qiniu.com)

ps: 使用hexo的第三方theme,看起来不错的主题 hexo-theme-yilia,部署后就么么哒~~
https://github.com/litten/hexo-theme-yilia