2013-01-17 85 views
-2

這是關於約會。在android中查看數據庫

我有5個頁面依次鏈接。

在第4頁中,數據從用戶在第3頁中給出的數據進入數據庫。

用戶確認預約日期和時間,用戶應查看列表視圖形式的數據庫之前...

這是我所編碼。你能幫我解決嗎?

我的基本適配器類:

public class viewlistadapter extends BaseAdapter 
{ 
SQLiteDatabase sdb; 

private Context viewcontext; 
ArrayList v1=new ArrayList(); 
ArrayList v2=new ArrayList(); 
ArrayList v3=new ArrayList(); 
ArrayList v4=new ArrayList(); 
ArrayList v5=new ArrayList(); 

int length; 

public viewlistadapter(viewlist vl, ArrayList value12, ArrayList value22, ArrayList  value32, ArrayList value42, ArrayList value52) 
{ 
    viewcontext=vl; 
    v1=value12; 
    v2=value22; 
    v3=value32; 
    v4=value42; 
    v5=value52; 
    length=v1.size(); 

} 
public viewlistadapter(viewlist vl, String value12, String value22, 
     String value32, String value42, String value52) 
    { 
    // TODO Auto-generated constructor stub 
} 
public int getCount() 
    { 
    // TODO Auto-generated method stub 
    return length; 
} 

public Object getItem(int arg0) 
    { 
    // TODO Auto-generated method stub 
    return null; 
} 

public long getItemId(int position) 
    { 
    // TODO Auto-generated method stub 
    return 0; 
} 

public View getView(int position, View convertView, ViewGroup parent) 
    { 
    // TODO Auto-generated method stub 

    LinearLayout l=new LinearLayout(viewcontext); 

    TextView tv1=new TextView(viewcontext); 
    TextView tv2=new TextView(viewcontext); 
    TextView tv3=new TextView(viewcontext); 
    TextView tv4=new TextView(viewcontext); 
    TextView tv5=new TextView(viewcontext); 

    tv1.setText((String) v1.get(position)); 
    tv2.setText((String) v2.get(position)); 
    tv3.setText((String) v3.get(position)); 
    tv4.setText((String) v4.get(position)); 
    tv5.setText((String) v5.get(position)); 

    l.addView(tv1); 
    l.addView(tv2); 
    l.addView(tv3); 
    l.addView(tv4); 
    l.addView(tv5); 

    return l; 

} 
} 

和活動類是

public class viewlist extends Activity 
{ 
TextView viewtv1; 
Button viewbutt; 
ListView lv; 
TextView statustv; 
viewlistadapter vla; 
SQLiteDatabase db=null; 
SQLiteDatabase sdb; 
final String path="/data/data/a.b.seventeenth/databases/"; 
final String dbname="checking2.db"; 

ArrayList value12=new ArrayList(); 
ArrayList value22=new ArrayList(); 
ArrayList value32=new ArrayList(); 
ArrayList value42=new ArrayList(); 
ArrayList value52=new ArrayList(); 

public void createdb() 
{ 
    try 
    { 
     sdb=openOrCreateDatabase("checking2.db",Context.MODE_PRIVATE, null); 


    } 
    catch (Exception e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     Toast.makeText(getApplicationContext(), e.toString(), 5000).show(); 
    } 

} 


public void viewdb() 
{ 
    try 
    { 
     sdb=openOrCreateDatabase("checking2.db",Context.MODE_PRIVATE, null); 
     lv=(ListView) findViewById(R.id.lv);   



     String res=""; 
     Cursor c=sdb.query("login",null, null, null, null, null, null); 
     c.moveToFirst(); 
     while(!c.isAfterLast()) 
     { 
      value12.add(c.getString(c.getColumnIndex("name"))); 
      value22.add(c.getString(c.getColumnIndex("date"))); 
      value32.add(c.getString(c.getColumnIndex("month"))); 
      value42.add(c.getString(c.getColumnIndex("hours"))); 
      value52.add(c.getString(c.getColumnIndex("minutes"))); 
      c.moveToNext(); 
      /*status=sdb.view("login", null, value12); 
      return status;*/ 
      //long s=sdb.insertOrThrow("login", null, value12);    //long s= sdb.view("login", null, value12); 
     } 

     lv.setAdapter(new viewlistadapter(this,value12,value22,value32,value42,value52)); 


    } 
    catch (Exception e) 
    { 
     // TODO Auto-generated catch block 
     Toast.makeText(getApplicationContext(), e.toString(), 500000).show(); 
    } 

} 

    protected void onCreate(Bundle savedInstanceState) 
    { 
    // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.listviewform); 

     viewbutt=(Button) findViewById(R.id.viewbutt); 
     lv=(ListView) findViewById(R.id.lv); 
     statustv=(TextView) findViewById(R.id.statustv); 


     try 
     { 
      sdb=SQLiteDatabase.openDatabase(path+dbname,null ,SQLiteDatabase.OPEN_READONLY); 
     } 

     catch (Exception e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    /* 
     try { 
      if(db==null) 
      { 

      statustv.setText("no one has booked the appointment for today!!"); 

      } 
      else 
      { 
       viewdb(); 

      } 
     } catch (Exception e1) { 
      // TODO Auto-generated catch block 
      Toast.makeText(getApplicationContext(), e1.toString(), 500000).show(); 
     } 
    */ 
     //statustv.setText(text, type) 
    try { 
     viewbutt.setOnClickListener(new OnClickListener() 
     {    
      public void onClick(View v) 
      { 
       // TODO Auto-generated method stub 
       try 
       { 
        Bundle b=viewlist.this.getIntent().getExtras(); 
        String name=b.getString("name"); 
        int date=b.getInt("date"); 
        int month=b.getInt("month"); 
        int hour=b.getInt("hour"); 
        int minutes=b.getInt("minutes"); 
        Intent i=new Intent(getApplicationContext(),register.class); 

        //Toast.makeText(getApplicationContext(), String.valueOf(date)+String.valueOf(hour)+String.valueOf(minutes), 5000).show(); 

        i.putExtra("name",name); 
        /*a.putExtra("phone_no",phone_no); 
        a.putExtra("email", email);*/ 
        i.putExtra("date", date); 
        i.putExtra("month", month); 
        i.putExtra("hour", hour); 
        i.putExtra("minutes", minutes); 
        i.putExtra("name", name); 

        startActivity(i); 
       } catch (Exception e) 
       { 
        // TODO Auto-generated catch block 
        Toast.makeText(getApplicationContext(), e.toString(), 5000).show(); 
       } 
      } 
     }); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     Toast.makeText(getApplicationContext(), e.toString(), 500000).show(); 
    } 
} 

}

+0

這個問題真的很廣泛。在發佈問題之前,您應該儘可能縮小範圍。 – fiddler

+0

當然我會拿c是它的naext時間,小提琴手...你能幫我解決它嗎...請... – elegance

回答

0

首先,我們可以嘗試this.Program 「源碼瀏覽器」 即可顯示該數據數據庫。你可以在這裏下載(http://sourceforge.net/projects/sqlitebrowser/)。它很容易使用。

2 .. 打開CMD去編程工具......

D:\Android Setup\android-sdk_r17-windows\android-sdk-windows\platform-tools>adb 
shell 
# cd data 
cd data 
# cd data 
cd data 
# cd com.maid.testnews(package name) 
cd com.maid.testnews 
# cd databases 
cd databases 
# sqlite3 Maidnews(Database name) 
sqlite3 Maidnews 
SQLite version 3.6.22 
Enter ".help" for instructions 
Enter SQL statements terminated with a ";" 

sqlite> select * from maidtitle;(table name) 

看到你的結果....

3. 在Eclipse看看文件瀏覽器選項卡(靠近控制檯選項卡)。或者看菜單「窗口 - >顯示視圖 - >其他... - >文件資源管理器」。模擬器應該運行。在文件資源管理器窗口中,轉到文件夾「data/data/[your_package_name]/databases /」。在那裏你可以找到你的數據庫。您可以將它導出到您的電腦。在窗口的右上角有一個按鈕「從設備中拉出文件」。選擇數據庫,單擊該按鈕並在計算機上保存數據庫。

+0

thnk你maid786我thnk我的問題是不正確的,或者你還沒有明白什麼我想....我想查看數據庫中的數據在工作應用程序中的列表視圖格式.... – elegance