-2

是关于约会的。

我有 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();
    }
}

}

4

1 回答 1

0

首先我们可以试试这个。程序“sqlite browser”可以显示数据库中的数据。你可以在这里下载(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 中查看 File Explorer 选项卡(靠近 Console 选项卡)。或查看菜单“窗口 -> 显示视图 -> 其他... -> 文件资源管理器”。应该运行模拟器。在文件资源管理器窗口中,转到文件夹“data/data/[your_package_name]/databases/”。在那里你可以找到你的数据库。您可以将其导出到您的计算机。在窗口的右上角有一个按钮“从设备中提取文件”。选择数据库,单击该按钮并在计算机上保存数据库。

于 2013-01-17T11:36:53.243 回答