流式布局 并添加到数据库

布局

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">


    <EditText
        android:id="@+id/edit_keys"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>
    <Button
        android:id="@+id/btn_search"
        android:layout_width="80dp"
        android:layout_height="50dp"
        android:text="搜索"/>
</LinearLayout>

<TextView
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:textSize="20sp"
    android:gravity="center_vertical"
    android:paddingLeft="20dp"
    android:text="搜索历史"/>

<com.lll.flowlayout02.FlowLayout
    android:id="@+id/flow_history_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    flow:textSize="20sp"
    android:layout_weight="1">


</com.lll.flowlayout02.FlowLayout>

<TextView
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:paddingLeft="20dp"
    android:textSize="20sp"
    android:gravity="center_vertical"
    android:text="热门搜索"/>
<com.lll.flowlayout02.FlowLayout
    android:id="@+id/flow_hot_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:text="apple"
    android:background="@drawable/btn_bg"
    android:textSize="20sp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="vivo"
        android:background="@drawable/btn_bg"
        android:textSize="20sp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="oppo"
        android:background="@drawable/btn_bg"
        android:textSize="20sp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="小米"
        android:background="@drawable/btn_bg"
        android:textSize="20sp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="华为"
        android:background="@drawable/btn_bg"
        android:textSize="20sp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="笔记本"
        android:background="@drawable/btn_bg"
        android:textSize="20sp" />
</com.lll.flowlayout02.FlowLayout>
<Button
    android:id="@+id/clear"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="清除历史记录"/>
**自定义属性** attrs <?xml version="1.0" encoding="utf-8"?>

Shape

<?xml version="1.0" encoding="utf-8"?>

<stroke
    android:color="@color/colorAccent"
    android:width="2dp"></stroke>
**样式** <?xml version="1.0" encoding="utf-8"?>

FlowLayout页面

package com.lll.flowlayout02;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

public class FlowLayout extends FrameLayout {
//设置水平距离
int H_DISTANCE = 20;
//设置竖直距离
int V_DISTANCE = 20;
private float mTextSize;

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

public FlowLayout(Context context,AttributeSet attrs) {
    super(context, attrs);
    TypedArray array=context.obtainStyledAttributes(attrs, R.styleable.flow);
    mTextSize = array.getDimension(R.styleable.flow_textSize, 0);
}

public FlowLayout(Context context,AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray array=context.obtainStyledAttributes(attrs, R.styleable.flow);
    mTextSize = array.getDimension(R.styleable.flow_textSize, 0);//得到的值单位是像素
}
public void addTextView(String keys){
    //加载xml的布局
    TextView textView = (TextView) View.inflate(getContext(), R.layout.flow_item, null);
    textView.setText(keys);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,mTextSize);
    //设置布局的自适应宽高
    LayoutParams params = new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
    //控件设置上布局的参数
    textView.setLayoutParams(params);

    this.addView(textView);
}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    //获取本控件的宽度
    int width = getWidth();
    //行数
    int row = 0;
    //子控件左边的坐标
    int disWidth = H_DISTANCE;
    for (int i=0;i<getChildCount();i++){
        //查找子控件
        View view = getChildAt(i);
        int viewWidth = view.getWidth();
        int viewHeight = view.getHeight();
        //判断右边的控件宽度是否超过了屏幕的宽度
        if (disWidth + viewWidth > width){
            //行数增加
            row++;
            //还远左边坐标
            disWidth = H_DISTANCE;
        }
       int viewTop = row * viewHeight+row * V_DISTANCE;
        view.layout(disWidth,viewTop,disWidth+viewWidth,viewTop+viewHeight);
        //记录下一次子控件左边的坐标
        disWidth += (viewWidth+H_DISTANCE);
    }
}

}

数据库
MySqlite

package com.lll.flowlayout02;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MySqlite extends SQLiteOpenHelper {
public MySqlite(Context context) {
super(context, “fl.db”, null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
      db.execSQL("CREATE TABLE fl(personid INTEGER PRIMARY KEY AUTOINCREMENT,name VARCHAR(100))");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}

}

Dao层
package com.lll.flowlayout02;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class Dao {

private final SQLiteDatabase db;

public Dao(Context context) {
    //创建对象
    MySqlite mySqlite = new MySqlite(context);
    db = mySqlite.getWritableDatabase();
}

//写方法
//增
public long insert(String table, String nullColumnHack, ContentValues values) {
    return db.insert(table, nullColumnHack, values);
}

//删
public long delete(String table, String whereClause, String[] whereArgs) {
    return db.delete(table, whereClause, whereArgs);
}

//改
public long update(String table, ContentValues values, String whereClause, String[] whereArgs) {
    return db.update(table, values, whereClause, whereArgs);
}

//查
public Cursor query(String table, String[] columns, String selection,
                    String[] selectionArgs, String groupBy, String having,
                    String orderBy) {
    return db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
}

}

MainActivity页面

package com.lll.flowlayout02;

import android.content.ContentValues;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

private EditText edit;
private Button btn_search;
private Button clear;
private FlowLayout flow_history;
private long insert;
private Dao dao;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //找控件
    edit = findViewById(R.id.edit_keys);
    flow_history = findViewById(R.id.flow_history_layout);
    btn_search = findViewById(R.id.btn_search);
    clear = findViewById(R.id.clear);
    btn_search.setOnClickListener(this);
    clear.setOnClickListener(this);
    //创建Dao层
    dao = new Dao(MainActivity.this);

    //查询数据库
    //创建Dao层
    Dao dao = new Dao(MainActivity.this);
    Cursor query = dao.query("fl", null, null, null, null, null, null);
    if (query.moveToFirst()){
        do {
            String name = query.getString(query.getColumnIndex("name"));
            flow_history.addTextView(name);
        }while (query.moveToNext());
    }
}

@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.btn_search:
            String keys = edit.getText().toString();
            if (keys.equals("")||keys == ""){
                Toast.makeText(MainActivity.this,"输入框不能为空",Toast.LENGTH_LONG).show();
                return;
            }
            flow_history.addTextView(keys);
            //点击搜索将内容添加到数据库
            ContentValues values = new ContentValues();
            values.put("name",keys);
            insert = dao.insert("fl", null, values);
            Toast.makeText(this,"添加成功",Toast.LENGTH_SHORT).show();
            break;
        case R.id.clear:
            long delete = dao.delete("fl", null, null);
            Toast.makeText(this,"删除条数为"+delete,Toast.LENGTH_SHORT).show();
            flow_history.removeAllViews();
            break;
    }
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
4S店客户管理小程序-毕业设计,基于微信小程序+SSM+MySql开发,源码+数据库+论文答辩+毕业论文+视频演示 社会的发展和科学技术的进步,互联网技术越来越受欢迎。手机也逐渐受到广大人民群众的喜爱,也逐渐进入了每个用户的使用。手机具有便利性,速度快,效率高,成本低等优点。 因此,构建符合自己要求的操作系统是非常有意义的。 本文从管理员、用户的功能要求出发,4S店客户管理系统中的功能模块主要是实现管理员服务端;首页、个人中心、用户管理、门店管理、车展管理、汽车品牌管理、新闻头条管理、预约试驾管理、我的收藏管理、系统管理,用户客户端:首页、车展、新闻头条、我的。门店客户端:首页、车展、新闻头条、我的经过认真细致的研究,精心准备和规划,最后测试成功,系统可以正常使用。分析功能调整与4S店客户管理系统实现的实际需求相结合,讨论了微信开发者技术与后台结合java语言和MySQL数据库开发4S店客户管理系统的使用。 关键字:4S店客户管理系统小程序 微信开发者 Java技术 MySQL数据库 软件的功能: 1、开发实现4S店客户管理系统的整个系统程序; 2、管理员服务端;首页、个人中心、用户管理、门店管理、车展管理、汽车品牌管理、新闻头条管理、预约试驾管理、我的收藏管理、系统管理等。 3、用户客户端:首页、车展、新闻头条、我的 4、门店客户端:首页、车展、新闻头条、我的等相应操作; 5、基础数据管理:实现系统基本信息的添加、修改及删除等操作,并且根据需求进行交流信息的查看及回复相应操作。
现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本微信小程序医院挂号预约系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此微信小程序医院挂号预约系统利用当下成熟完善的SSM框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的MySQL数据库进行程序开发。微信小程序医院挂号预约系统有管理员,用户两个角色。管理员功能有个人中心,用户管理,医生信息管理,医院信息管理,科室信息管理,预约信息管理,预约取消管理,留言板,系统管理。微信小程序用户可以注册登录,查看医院信息,查看医生信息,查看公告资讯,在科室信息里面进行预约,也可以取消预约。微信小程序医院挂号预约系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值