2012-04-01 4 views
0

Ich verwende den folgenden Code, um eine ListView in CustomAlertDialog Layout zu verwenden.Verwenden von ListView in CustomAlertDialog Layout

public void onButtonClicked(View v) { 
    Toast.makeText(this, 
      Messages.getString("OSListActivity.195"), Toast.LENGTH_SHORT).show(); //$NON-NLS-1$ 
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View view = inflater.inflate(R.layout.buttondialog, null); 
    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setView(view); 
    ListView mbListView = (ListView) view.findViewById(R.id.mblist); 
    builder.setTitle(Messages.getString("OSListActivity.196")) 
      .setNeutralButton(Messages.getString("OSListActivity.197"), 
        null); 
    MatrixCursor dcursor = propmanager.propCursor(); 
    if (dcursor.moveToFirst()) { 
     startManagingCursor(dcursor); 
     String[] from = { "name", "value" }; 
     int[] to = { R.id.mbname, R.id.mbvalue }; 
     SimpleCursorAdapter dadapter = new SimpleCursorAdapter(this, 
       R.layout.mblistrow, dcursor, from, to); 
     mbListView.setAdapter(dadapter); 
    } 
    builder.show(); //$NON-NLS-1$ //$NON-NLS-2$ 
} 

Allerdings bekomme ich den folgenden Fehler. Warum? Was mache ich hier falsch?

03-30 18:45:50.867: E/AndroidRuntime(11170): at android.view.View$PerformClick.run(View.java:14105) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at android.os.Handler.handleCallback(Handler.java:605) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at android.os.Handler.dispatchMessage(Handler.java:92) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at android.os.Looper.loop(Looper.java:137) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at android.app.ActivityThread.main(ActivityThread.java:4424) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at java.lang.reflect.Method.invokeNative(Native Method) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at java.lang.reflect.Method.invoke(Method.java:511) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at dalvik.system.NativeStart.main(Native Method) 
03-30 18:45:50.867: E/AndroidRuntime(11170): Caused by: java.lang.reflect.InvocationTargetException 
03-30 18:45:50.867: E/AndroidRuntime(11170): at java.lang.reflect.Method.invokeNative(Native Method) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at java.lang.reflect.Method.invoke(Method.java:511) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at android.view.View$1.onClick(View.java:3039) 
03-30 18:45:50.867: E/AndroidRuntime(11170): ... 11 more 
03-30 18:45:50.867: E/AndroidRuntime(11170): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist 
03-30 18:45:50.867: E/AndroidRuntime(11170): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:267) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at android.widget.CursorAdapter.init(CursorAdapter.java:168) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at android.widget.CursorAdapter.<init>(CursorAdapter.java:116) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at android.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:52) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:78) 
03-30 18:45:50.867: E/AndroidRuntime(11170): at com.manager.boot.free.MultiBootManager.onButtonClicked(MultiBootManager.java:103) 
03-30 18:45:50.867: E/AndroidRuntime(11170): ... 14 more 

Antwort

0

Sie versuchen, einen Cursor zu verwenden, die eine Spalte _id genannt erfordert. Fügen Sie eine Spalte (_id) in Ihrer Tabelle hinzu oder schließen Sie Ihre Primärschlüsselspalte in die Abfrage ein (yourColumn AS _id), um dieses Problem zu beheben. Für more info

Verwandte Themen