Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx

上传人:b****2 文档编号:3212461 上传时间:2023-05-01 格式:DOCX 页数:31 大小:80.09KB
下载 相关 举报
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第1页
第1页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第2页
第2页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第3页
第3页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第4页
第4页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第5页
第5页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第6页
第6页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第7页
第7页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第8页
第8页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第9页
第9页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第10页
第10页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第11页
第11页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第12页
第12页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第13页
第13页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第14页
第14页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第15页
第15页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第16页
第16页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第17页
第17页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第18页
第18页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第19页
第19页 / 共31页
Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx_第20页
第20页 / 共31页
亲,该文档总共31页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx

《Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx(31页珍藏版)》请在冰点文库上搜索。

Android流布局FlowLayout在搜索历史中的应用0920Word文档下载推荐.docx

db.execSQL(

"

createtablekw(_idintegerprimarykeyautoincrement,keywordvarchar,inputnointeger)"

);

//插入初始数据

db.execSQL("

insertintokw(keyword,inputno)values('

book'

'

0'

)"

书本'

publicvoidonUpgrade(SQLiteDatabasedb,intoldVersion,intnewVersion){

//升级

}

Kw.java

*Createdby钧on2016/9/18.

*关键词实体类

publicclassKw{

publicintid;

publicStringkeyword;

publicintinputno;

publicintgetId(){

returnid;

publicvoidsetId(intid){

this.id=id;

publicStringgetKeyword(){

returnkeyword;

publicvoidsetKeyword(Stringkeyword){

this.keyword=keyword;

publicintgetInputno(){

returninputno;

publicvoidsetInputno(intinputno){

this.inputno=inputno;

publicStringtoString(){

return"

Kw{"

+

id="

+id+

keyword='

"

+keyword+'

\'

'

inputno="

+inputno+

'

}'

;

KwDao.java

*封装对关键词表的数据库访问操作

publicclassKwDao{

publicKwDao(){}

publicKwDao(Contextcontext){

this.context=context;

privateContextcontext;

privateStringtablename="

kw"

*判断数据库中是否存在key

*@paramkey

*@return

publicbooleancontains(Stringkey){

List<

Kw>

list=newArrayList<

();

//实例化辅助类

DBHelperhelper=newDBHelper(context);

//获取SQLite数据库对象

SQLiteDatabasedb=helper.getReadableDatabase();

//执行查询命令,接收游标返回

Cursorcursor=db.rawQuery("

selectcount(*)from"

+this.tablename

+"

wherekeyword='

+key+"

null);

intnumber=0;

while(cursor.moveToNext()){//moveToNext:

移动到下一行

number=cursor.getInt(0);

//count(*)

cursor.close();

//游标关闭

db.close();

//db关闭

if(number==0){

returnfalse;

}else{

returntrue;

*插入一个全新的关键词

publiclonginsert(Stringkey){

//准备插入的数据

ContentValuesvalues=newContentValues();

//

values.put("

keyword"

key);

inputno"

1);

longid=db.insert(tablename,null,values);

Log.i("

spl"

"

insertid="

+id);

//关闭连接

*增加某个关键词的使用频度

publicvoidupdate(Stringkey){

updatekwsetinputno=inputno+1wherekeyword='

*根据"

用户的输入"

返回和这个词相关的关键词集合

publicList<

select(Stringkey){

select*from"

wherekeywordlike'

%"

%'

orderbyinputnodescLIMIT10"

Kwkw=newKw();

kw.setId(cursor.getInt(0));

kw.setKeyword(cursor.getString

(1));

kw.setInputno(cursor.getInt

(2));

list.add(kw);

//添加到集合

returnlist;

MyAdapter.java

流布局,核心类

*Createdbytaofangxinon16/4/16.

*自定义布局:

组件自动换行

publicclassFlowLayoutextendsViewGroup{

privateContextmContext;

privateintusefulWidth;

//thespaceofalinewecanuse(line'

swidthminusthesumofleftandrightpadding

//行间距

privateintlineSpacing=0;

//thespacingbetweenlinesinflowlayout

View>

childList=newArrayList();

Integer>

lineNumList=newArrayList();

publicFlowLayout(Contextcontext){

this(context,null);

publicFlowLayout(Contextcontext,AttributeSetattrs){

this(context,attrs,0);

publicFlowLayout(Contextcontext,AttributeSetattrs,intdefStyleAttr){

super(context,attrs,defStyleAttr);

mContext=context;

TypedArraymTypedArray=context.obtainStyledAttributes(attrs,

R.styleable.FlowLayout);

//给行间距赋值

//lineSpacing=mTypedArray.getDimensionPixelSize(

//R.styleable.FlowLayout_lineSpacing,0);

lineSpacing=30;

//px这里被我修改成固定的值了

mTypedArray.recycle();

protectedvoidonMeasure(intwidthMeasureSpec,intheightMeasureSpec){

intmPaddingLeft=getPaddingLeft();

intmPaddingRight=getPaddingRight();

intmPaddingTop=getPaddingTop();

intmPaddingBottom=getPaddingBottom();

intwidthSize=MeasureSpec.getSize(widthMeasureSpec);

intheightMode=MeasureSpec.getMode(heightMeasureSpec);

intheightSize=MeasureSpec.getSize(heightMeasureSpec);

intlineUsed=mPaddingLeft+mPaddingRight;

intlineY=mPaddingTop;

intlineHeight=0;

for(inti=0;

i<

this.getChildCount();

i++){

Viewchild=this.getChildAt(i);

if(child.getVisibility()==GONE){

continue;

intspaceWidth=0;

intspaceHeight=0;

LayoutParamschildLp=child.getLayoutParams();

if(childLpinstanceofMarginLayoutParams){

measureChildWithMargins(child,widthMeasureSpec,0,heightMeasureSpec,lineY);

MarginLayoutParamsmlp=(MarginLayoutParams)childLp;

spaceWidth=mlp.leftMargin+mlp.rightMargin;

spaceHeight=mlp.topMargin+mlp.bottomMargin;

}else{

measureChild(child,widthMeasureSpec,heightMeasureSpec);

intchildWidth=child.getMeasuredWidth();

intchildHeight=child.getMeasuredHeight();

spaceWidth+=childWidth;

spaceHeight+=childHeight;

if(lineUsed+spaceWidth>

widthSize){

//approachthelimitofwidthandmovetonextline

lineY+=lineHeight+lineSpacing;

lineUsed=mPaddingLeft+mPaddingRight;

lineHeight=0;

if(spaceHeight>

lineHeight){

lineHeight=spaceHeight;

lineUsed+=spaceWidth;

setMeasuredDimension(

widthSize,

heightMode==MeasureSpec.EXACTLY?

heightSize:

lineY+lineHeight+mPaddingBottom

);

protectedvoidonLayout(booleanchanged,intl,intt,intr,intb){

intlineX=mPaddingLeft;

intlineWidth=r-l;

usefulWidth=lineWidth-mPaddingLeft-mPaddingRight;

intlineNum=0;

lineNumList.clear();

intleft=0;

inttop=0;

intright=0;

intbottom=0;

left=lineX+mlp.leftMargin;

top=lineY+mlp.topMargin;

right=lineX+mlp.leftMargin+childWidth;

bottom=lineY+mlp.topMargin+childHeight;

left=lineX;

top=lineY;

right=lineX+childWidth;

bottom=lineY+childHeight;

lineWidth){

lineNumList.add(lineNum);

lineX=mPaddingLeft;

lineNum=0;

child.layout(left,top,right,bottom);

lineNum++;

lineX+=spaceWidth;

//addthenumoflastline

*resortchildelementstouselinesasfewaspossible

publicvoidrelayoutToCompress(){

intchildCount=this.getChildCount();

if(0==childCount){

//noneedtosortifflowlayouthasnochildview

return;

intcount=0;

childCount;

Viewv=getChildAt(i);

if(vinstanceofBlankView){

//BlankViewisjusttomakechildslookinalignment,weshouldignorethemwhenwerelayout

count++;

View[]childs=newView[count];

int[]spaces=newint[count];

intn=0;

childs[n]=v;

LayoutParamschildLp=v.getLayoutParams();

intchildWidth=v.getMeasuredWidth();

MarginLayoutParamsmlp=(MarginLayoutParams)childLp;

spaces[n]=mlp.leftMargin+childWidth+mlp.rightMargin;

spaces[n]=childWidth;

n++;

int[]compressSpaces=newint[count];

count;

compressSpaces[i]=spaces[i]>

usefulWidth?

usefulWidth:

spaces[i];

sortToCompress(childs,compressSpaces);

this.rem

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2