2013-08-22 65 views
1

我找不出如何在我的Activity中使用EditText來搜索日期範圍的sqlite。我想我需要以某種方式製作editText1和2字符串,但我不知道如何在數據庫中執行此操作。使用EditText從SQLite中的兩個日期獲取數據

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 - 8 - 16' 這些靜態值與「2013 - 8 - 21這個完美的作品。我在我的arrayList中完美地顯示出它只是來自sqlite的靜態日期。

在我的活動,我有兩個EDITTEXT ...

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

,我有一個onClick的按鈕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); 




     }}); 
+1

在點擊鏈接就可以得到Editext 的價值'字符串值1 = edittext1.getText()。toString(); 字符串VALUE2 = edittext2.getText()。的toString()' 然後值傳遞給該方法 'getAllsaleweekly(值1,值2)' – Raghunandan

+0

應該完全是一個答案...謝謝。如果我被允許,你發佈的答案我會給你點。 – SmulianJulian

+0

我確實發佈了它作爲答案,很高興我能幫上忙 – Raghunandan

回答

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 
    } 
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+"'"; 
相關問題