20.11.2016 Views

ANDROID APP

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ฐานข้อมูล SQLite<br />

241<br />

import android.view.ViewGroup;<br />

import android.widget.BaseAdapter;<br />

import android.widget.TextView;<br />

import com.cookbook.data.Constants;<br />

import com.cookbook.data.MyDB;<br />

public class DisplayDiaries extends ListActivity {<br />

MyDB dba;<br />

DiaryAdapter myAdapter;<br />

private class MyDiary{<br />

public MyDiary(String t, String c, String r){<br />

title=t;<br />

content=c;<br />

recorddate=r;<br />

}<br />

public String title;<br />

public String content;<br />

public String recorddate;<br />

}<br />

@Override<br />

protected void onCreate(Bundle savedInstanceState) {<br />

dba = new MyDB(this);<br />

dba.open();<br />

setContentView(R.layout.diaries);<br />

}<br />

super.onCreate(savedInstanceState);<br />

myAdapter = new DiaryAdapter(this);<br />

this.setListAdapter(myAdapter);<br />

private class DiaryAdapter extends BaseAdapter {<br />

private LayoutInflater mInflater;<br />

private ArrayList diaries;<br />

public DiaryAdapter(Context context) {<br />

mInflater = LayoutInflater.from(context);<br />

diaries = new ArrayList();<br />

getdata();<br />

}<br />

public void getdata(){<br />

Cursor c = dba.getdiaries();<br />

startManagingCursor(c);<br />

if(c.moveToFirst()){<br />

do{<br />

String title =<br />

c.getString(c.getColumnIndex(Constants.TITLE_NAME));

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!