2017-05-24 64 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

删除该行,然后再试一次。 –

相关问题