1

我不知道如何在我的活动中使用 EditText 来搜索 sqlite 的日期范围。我想我需要以某种方式制作 editText1 和 2 个字符串,但我不知道如何在我的数据库中做到这一点。

在sqlite中

public ArrayList<HashMap<String, String>> getAllsaleweekly() {
    ArrayList<HashMap<String, String>> wordList;
    GregorianCalendar gc = new GregorianCalendar();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MMM-dd");
    String today = sdf.format(gc.getTime());
    wordList = new ArrayList<HashMap<String, String>>();
    String selectQuery = "SELECT * FROM INSERTS WHERE saleDate BETWEEN '2012-Aug-16' AND '2013-Aug-21'";

这很完美,除了我不想要 2012-Aug-16' 和 '2013-Aug-21 的静态值。我完美地显示在我的 arrayList 中,它只是来自 sqlite 的静态日期。

在我的活动中,我有两个editText ...

EditText editText1,editText2;
edittext1 =(EditText)findViewById(R.id.editText1);
edittext2 =(EditText)findViewById(R.id.editText2);

我有一个 onClick for Button bydate

bydate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v){
            ArrayList<HashMap<String, String>> saleList =  controller.getAllsaleweekly();
            ListAdapter adapter = new SimpleAdapter(whatever.this,whateverList, R.layout.whatever, new String[] {"whatever","whatever", "whatever", "whatever","whatever","whatever", "whatever"},  new int[] { R.id.whatever, R.id.whatever, R.id.whatever, R.id.whatever,R.id.whatever, R.id.v, R.id.whatever}); 
setListAdapter(adapter);




        }}); 
4

2 回答 2

1

修改你的onClickListener

    bydate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v){
          String date1 = edittext1.getText().toString(); 
          String date2 = edittext2.getText().toString();
          if(date1 != null && date2 != null){ 
                ArrayList<HashMap<String, String>> saleList =  controller.getAllsaleweekly(date1 ,date2);
                ListAdapter adapter = new SimpleAdapter(whatever.this,whateverList, R.layout.whatever, new String[] {"whatever","whatever", "whatever", "whatever","whatever","whatever", "whatever"},  new int[] { R.id.whatever, R.id.whatever, R.id.whatever, R.id.whatever,R.id.whatever, R.id.v, R.id.whatever}); 
    setListAdapter(adapter);
}

        }}); 

public ArrayList<HashMap<String, String>> getAllsaleweekly(String date1,String date2) {
    ArrayList<HashMap<String, String>> wordList;
    GregorianCalendar gc = new GregorianCalendar();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MMM-dd");
    String today = sdf.format(gc.getTime());
    wordList = new ArrayList<HashMap<String, String>>();
    String selectQuery = "SELECT * FROM INSERTS WHERE saleDate BETWEEN '" + date1 +"' AND '"+date2+"'";
于 2013-08-22T04:28:03.430 回答
1

在按钮单击时,您可以获得 Editext 的值

  String value1 = edittext1.getText().toString();
  String value2 = edittext2.getText().toString(); 

然后

  controller.getAllsaleweekly(value1,value2); 

改变

  public ArrayList<HashMap<String, String>> getAllsaleweekly(String date1,String date2)   
  {

   // use date1 and date 2 here
  }
于 2013-08-22T04:29:06.887 回答