onCreate 함수에서 테이블 (학생)이있는 데이터베이스 (mydb)를 만든 다음 button click.Now를 사용하여 값을 동적으로 입력했습니다. 테이블에있는 학생이 버튼을 클릭하여 listview에 표시하십시오.SQLite 데이터베이스에서 데이터 가져 오기 및 ListView에 표시 --android
public class MainActivity extends Activity
{
String name, phone;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db=openOrCreateDatabase("mydb", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS student(dbname VARCHAR, dbphone VARCHAR);");
}
public void btnaddtodb(View v)
{
EditText edtxtname = (EditText)findViewById(R.id.edtxtname);
EditText edtxtphone = (EditText)findViewById(R.id.edtxtphone);
name=edtxtname.getText().toString();
phone=edtxtphone.getText().toString();
db.execSQL("INSERT INTO student values('"+name+"','"+phone+"');");
edtxtname.setText("");
edtxtphone.setText("");
}
}
당신은 어떤 자습서를 시도 :
가장 간단한 예제 5 월은 다음과 같습니다? – GrIsHu
지금까지 무엇을 했습니까? 문제/오류는 무엇입니까? –
시도해 보았습니다 .. bt got confused – danish