1. 模糊搜索
DAO页面
package com.avicsafety.dao;
import java.util.List;
import org.xutils.DbManager;
import org.xutils.ex.DbException;
import com.avicsafety.model.M_MajorHazard;
public class D_Major_Hazard{
public List
List
return list;
}
public M_MajorHazard getModel(DbManager db,int id) throws DbException{
M_MajorHazard model = db.selector(M_MajorHazard.class).where("id","=",id).findFirst();
return model;
}
}
model页面
package com.avicsafety.model;
import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;
@Table(name="major_hazard")
public class M_MajorHazard {
@Column(name = "id",isId=true)
private int id;
@Column(name = "name")
private String name;
@Column(name = "anotherName")
private String anotherName;
@Column(name = "thresholdQuantity")
private String thresholdQuantity;
@Column(name = "correctionCoefficient")
private int correctionCoefficient;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAnotherName() {
return anotherName;
}
public void setAnotherName(String anotherName) {
this.anotherName = anotherName;
}
public String getThresholdQuantity() {
return thresholdQuantity;
}
public void setThresholdQuantity(String thresholdQuantity) {
this.thresholdQuantity = thresholdQuantity;
}
public int getCorrectionCoefficient() {
return correctionCoefficient;
}
public void setCorrectionCoefficient(int correctionCoefficient) {
this.correctionCoefficient = correctionCoefficient;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return this.name;
}
}
添加页面
package com.avicsafety.dangerous_chemicals;
import java.util.ArrayList;
import java.util.List;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import com.avicsafety.dao.D_Major_Hazard;
import com.avicsafety.lib.Adapter.CommonAdapter;
import com.avicsafety.lib.Adapter.ViewHolder;
import com.avicsafety.model.M_MajorHazard;
import com.avicsafety.service.MajorManager;
@ContentView(R.layout.activity_add_major_hazard)
public class MajorHazardActivity2 extends BaseActivity {
@ViewInject(R.id.editText1)
private EditText editText1;
@ViewInject(R.id.button_add)
private Button button_add;
@ViewInject(R.id.major_list)
private ListView major_list;
private CommonAdapter
private List
@Override
protected void InitializeData() {
button_add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String key= editText1.getText().toString();
refrechPage(key);
}
});
dataList = new ArrayList
major_list.setAdapter(mAdapter = new CommonAdapter
getApplicationContext(), dataList, R.layout.item_major_hazard) {
@Override
public void convert(ViewHolder helper, M_MajorHazard item) {
helper.setText(R.id.major_hazard_name, item.getName());
helper.setText(R.id.major_hazard_anotherName,
item.getAnotherName());
}
});
major_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
// TODO Auto-generated method stub
System.out.println();
Intent intent = new Intent();
intent.setClass(oThis, MajorHazardActivity.class);
startActivity(intent);
}
});
refrechPage("");
}
// 更新listview页面
private void refrechPage(String key) {
// 更新list
//查数据库 datalist = dao.
MajorManager manager = new MajorManager();
dataList = manager.getList(key);
mAdapter.setmDatas(dataList);
mAdapter.notifyDataSetChanged();
}
}
xml页面
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/FFFFFF"
android:orientation="vertical" >
android:layout_height="45dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="15dp" >
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="@drawable/bg_edittext"
android:ems="10"
android:hint="请输入危化品名称"
android:textSize="17sp" >
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_weight="0.2"
android:layout_marginLeft="5dp"
android:text="搜索"
android:textColor="#ffffff"
android:textSize="12dp"
app:buttonColor="Blue" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp" />
android:layout_width="match_parent"
android:layout_height="match_parent" />