2017-05-24 62 views
-6
public class SearchActivity extends AppCompatActivity { 
EditText recupdate; 
Button update; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_search); 

    recupdate = (EditText)findViewById(R.id.txtusername); 
    update = (Button)findViewById(R.id.btnupdate); 
    update.setOnClickListener(new View.OnClickListener(){ 
     @Override 
     public void onClick(View view){ 

      SQLiteDatabase fuuast = openOrCreateDatabase("MyDb", MODE_PRIVATE, null); 
      fuuast.execSQL("Create table if not exists std_rec(username varchar primary key, password varchar, age Integer, phone Integer) "); 
      String query = "Select * from std_rec Where username = '"+update.getText()+"'"; 
      fuuast.execSQL(query); 


      Intent i = new Intent(getApplicationContext(), MainActivity.class); 
      Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT).show(); 
      startActivity(i); 
     } 

    }); 
} 

如何顯示數據或在哪裏顯示請幫我想顯示的數據點擊搜索按鈕對不起我的英語後,我是AB初學者如何從數據庫中檢索數據並在textview或toast中顯示或在警報中顯示?

+0

你想在哪裏顯示數據?你能詳細說明一下嗎? – Akshay

+0

任何地方在相同的活動或警報或彈出窗口或textview –

+0

檢查下面的答案@AdilKhan –

回答

-1

請與查詢光標這將對您的數據

SQLiteDatabase db = openOrCreateDatabase("MyDb", MODE_PRIVATE, null); 
String selectQuery = "SELECT * FROM std_rec "; 

     Cursor cursor = db.rawQuery(selectQuery, null); 

     if(cursor !=null) { 
    cursor .moveToFirst(); 
    startManagingCursor(cursor); 
    for (int i=0; i<cursor .getCount(); i++) { 

    String message = cursor .getString(0); 
Toast.makeText(getApplicationContext(), message , Toast.LENGTH_SHORT).show();//Here display message as you like, in toast, alert or TextView 
} 
} 

希望這可以幫助

+0

我可以問誰和爲什麼downvoted? –

+0

getReadableDatabase它顯示紅色警報 –

+0

刪除該行,然後再試一次。 –

相關問題