package com.Nutrition;

import java.net.URLEncoder;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.Forgo3.R;

public class Search extends Activity {

 private static final String DATABASE_NAME = "Forgo3.sqlite";
 private static final String ALLSEARCH = "SELECT * FROM calorie";
 private static final String SEARCH = "SELECT * FROM calorie WHERE food = ?";
 private static final String CREATE = "CREATE TABLE IF NOT EXISTS calorie(food TEXT PRIMARY KEY, cal TEXT)";
 
 private TextView t;
 private EditText et;
 private String search[] = new String[1];
 private SQLiteDatabase db;
 private Cursor c;
 private String result1 = "";
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.search);
  
  C:\Users\내문서\Desktop\캡쳐.jpg
  search();
 
  //exit();
 }
 
 public void exit(){
  Button b = (Button)findViewById(R.id.searchback);
  b.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    finish();
   }
  });
 }
 
 public void search(){
  Button b = (Button)findViewById(R.id.searchback);
  b.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    
    
    t = (TextView)findViewById(R.id.searchresult);
    et = (EditText)findViewById(R.id.foodinput);
    
    t.setText("");
    
    
    db = openOrCreateDatabase(DATABASE_NAME,   SQLiteDatabase.CREATE_IF_NECESSARY, null);
    search[0] = et.getText().toString();
    
    c = db.rawQuery(SEARCH, search);
    if ( c != null )
    {
     if ( c.moveToFirst() )
     {
      for(int i =0; i < c.getColumnCount(); i++){
       result1 += c.getColumnName(i)+ "|";

      }
      result1 += "\n";
      t.setText(result1 );

      do{
       result1 = "";
       for(int i = 0 ; i < c.getColumnCount() ; i++ )
       {
        result1 += c.getString(i) + " | ";
       }
       result1 += "\n";
       t.setText( t.getText() + result1 );
      }while(c.moveToNext());

     }
    }
    c.close();
   }
  });
 
 }

}

대충 이런 소스인데 EditText에서 쌀밥이라고 치고 조회버튼을 누른고 TextView에 화면이 출력된뒤에

다시 보리밥이라고 치고 조회버튼을 누르면

캡처.JPG

이런식으로 초기화가 안되는데 이유좀 가르쳐주세요 ㅜ.ㅜ food랑 cal은 참고로 속성입니다 ㅜ.ㅜ