数据库点击问题

时间:2012-04-01 14:15:45

标签: android database click

public class Database extends Activity {
    private static final SimpleCursorAdapter SimpleCursorAdapter = null;
    TextView output;
    DatabaseHelper dbh = new DatabaseHelper(this);

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.database);

        ListView lv=(ListView)findViewById(R.id.mylist);
        lv.setClickable(true);

        Button button1 = (Button)findViewById(R.id.button1);
        button1.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {


        Intent intent=new Intent(Database.this,MainMenu.class);
            startActivity(intent);

            }
         });

       // Intent sender=getIntent();

        DatabaseHelper dbh = new DatabaseHelper(this);

        Cursor c = dbh.getReadableDatabase().rawQuery("SELECT _id, " + 
                        DatabaseHelper.NAME + 
                ", " + DatabaseHelper.VALUE1 + 
                ", " + DatabaseHelper.VALUE2 + 
                " FROM " +
                DatabaseHelper.TABLE_NAME, null); // initializing 


            String[] dataFrom ={DatabaseHelper.NAME, DatabaseHelper.VALUE1, DatabaseHelper.VALUE2};//, DatabaseHelper.VALUE3, DatabaseHelper.VALUE4, DatabaseHelper.VALUE5, DatabaseHelper.VALUE6, DatabaseHelper.VALUE7, DatabaseHelper.VALUE8, DatabaseHelper.VALUE9, DatabaseHelper.VALUE10, DatabaseHelper.VALUE11};
            int[] dataTo = {R.id.name, R.id.value1, R.id.value2};//, R.id.value3, R.id.value4, R.id.value5, R.id.value6, R.id.value7, R.id.value8, R.id.value9, R.id.value10, R.id.value11};

            SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
                    R.layout.row, c, dataFrom, dataTo);

            lv.setAdapter(adapter);

    }

    public void onListItemClick()
    {

    }
}

我已经创建了一个数据库表,并且我已经在屏幕上成功显示了它们。但是,当我点击一个条目时,我应该看到蓝色背景照明。当我点击一行时(我就像点击文本视图一样),我没有看到。有任何想法吗? 实际上,在单击表格中的一行后,我正在创建一个选项菜单。

错误日志: -

04-01 14:23:45.760: W/dalvikvm(930): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
04-01 14:23:45.789: E/AndroidRuntime(930): FATAL EXCEPTION: main
04-01 14:23:45.789: E/AndroidRuntime(930): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
04-01 14:23:45.789: E/AndroidRuntime(930):  at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
04-01 14:23:45.789: E/AndroidRuntime(930):  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3938)
04-01 14:23:45.789: E/AndroidRuntime(930):  at android.app.ActivityThread.access$1300(ActivityThread.java:123)
04-01 14:23:45.789: E/AndroidRuntime(930):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
04-01 14:23:45.789: E/AndroidRuntime(930):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 14:23:45.789: E/AndroidRuntime(930):  at android.os.Looper.loop(Looper.java:137)
04-01 14:23:45.789: E/AndroidRuntime(930):  at android.app.ActivityThread.main(ActivityThread.java:4424)
04-01 14:23:45.789: E/AndroidRuntime(930):  at java.lang.reflect.Method.invokeNative(Native Method)
04-01 14:23:45.789: E/AndroidRuntime(930):  at java.lang.reflect.Method.invoke(Method.java:511)
04-01 14:23:45.789: E/AndroidRuntime(930):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-01 14:23:45.789: E/AndroidRuntime(930):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-01 14:23:45.789: E/AndroidRuntime(930):  at dalvik.system.NativeStart.main(Native Method)
04-01 14:23:45.789: E/AndroidRuntime(930): Caused by: java.lang.NullPointerException
04-01 14:23:45.789: E/AndroidRuntime(930):  at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
04-01 14:23:45.789: E/AndroidRuntime(930):  at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
04-01 14:23:45.789: E/AndroidRuntime(930):  at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
04-01 14:23:45.789: E/AndroidRuntime(930):  ... 11 more
04-01 14:23:53.980: D/dalvikvm(962): GC_FOR_ALLOC freed 58K, 4% free 9066K/9347K, paused 167ms
04-01 14:23:53.990: I/dalvikvm-heap(962): Grow heap (frag case) to 9.453MB for 556016-byte allocation
04-01 14:23:54.090: D/dalvikvm(962): GC_CONCURRENT freed <1K, 4% free 9608K/9927K, paused 6ms+16ms
04-01 14:23:54.430: D/gralloc_goldfish(962): Emulator without GPU emulation detected.

1 个答案:

答案 0 :(得分:0)

关于您的蓝色照明。有一个错误,如果您使用 setClickable(true)不能点击它,但如果您使用 setClickable(false),则可以。它应该是另一种方式,但这只是出于某种原因。同样适用于 setFocusable (你不在这里使用,但无论如何)。