1. Nimm jetzt an unserem 2. ADVENT-Gewinnspiel teil - Alle Informationen findest Du hier!

ListView Example bearbeiten löst Exception aus

Dieses Thema im Forum "Android App Entwicklung" wurde erstellt von Terth, 04.08.2011.

  1. Terth, 04.08.2011 #1
    Terth

    Terth Threadstarter Neuer Benutzer

    Beiträge:
    16
    Erhaltene Danke:
    0
    Registriert seit:
    04.08.2011
    Hallo allerseits,

    Ich möchte eine Tablet app schreiben, die sich noch in der Planung befindet und nun ersteinmal eine Oberfläche zimmern um zu schauen ob User damit zurechtkommen. Die App soll aus mehreren Oberflächen bestehen zu denen über ein ListView navigiert werden soll. Das erste ist so eine Art Hauptmenü. Das Hautpemü besteht aus ListItems und ist an das Developer ListView Tutorial angelehnt. Die Informationen vom Hauptmenü werden über eine xml Datei geholt in denen das Array der MenüItems definiert ist. Jetzt möchte ich aber nicht nur ein TextView im ListItem haben sondern auch noch ein ImageView der einen Pfeil beinhaltet den ich mir als .png runtergeladen habe. Wenn ich das Einfüge und den Emulator starte kommmt:
    "Sorry! The application MedicWorkflow (process MedicWorkflow.Activities) has stopped unexpectedly. Please try again."
    Wenn ich den ganzen Kram ohne den ImageView und das Layout in list_item.xml laufen lasse und dem view seine ID wegnehme gehts, aber ich will ja noch einen Pfeil damit die Navigation besser aussieht.

    Hier ist mein Code:

    list_item.xml (Definition eines ListItems)

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:padding="6px"
        android:layout_height="67px" android:id="@+id/rlt_main"
        android:background="#000000">
    <TextView android:textSize="16sp" android:padding="10dp" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_alignTop="@+id/imageView1" android:layout_alignParentLeft="true" android:id="@+id/TextView_Name"></TextView>
    <ImageView android:src="@drawable/forward_arrow" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:id="@+id/imageView_Arrow"></ImageView>
    </RelativeLayout>
    MedicWorkflowActivity

    Code:
    package MedicWorkflow.Activities;
    
    import android.app.ListActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class MainMenuActivity extends ListActivity 
    {
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            String[] aMainMenu = getResources().getStringArray(R.array.menu_items);
            setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, aMainMenu));
            ListView lv = getListView();
            lv.setTextFilterEnabled(true);
            lv.setOnItemClickListener(new OnItemClickListener() 
            {
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
                {
                    String s = (String) ((TextView) view).getText();
                    Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
                }
            });
        }
        
    }
    string.xml

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="app_name">MedicWorkflow</string>
        <string-array name="menu_items">
            <item>Erstelle Muster</item>
            <item>Lade Muster</item>
            <item>Zeige Daten</item>
        </string-array>
    </resources>
    Ich danke für die Mithilfe
    Grüße Terth
     
  2. the_alien, 04.08.2011 #2
    the_alien

    the_alien Android-Lexikon

    Beiträge:
    1,559
    Erhaltene Danke:
    184
    Registriert seit:
    04.05.2009
    Ein Stacktrace aus dem Logcat ist immer hilfreich...

    Ist sp eine Einheit die ich nicht kenne?
    android:textSize="16sp"
     
  3. Terth, 04.08.2011 #3
    Terth

    Terth Threadstarter Neuer Benutzer

    Beiträge:
    16
    Erhaltene Danke:
    0
    Registriert seit:
    04.08.2011
    Also ich habe jetzt mal die Zeile wo der Text in den Toast geschrieben wird so geändert
    Code:
    String s = (String)((TextView)view.findViewById(R.id.TextView_Name)).getText();
                    Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
    weil ich dachte das man das besser über findViewById macht. Der LogCat eintrag zeigt das ich eine ResourceID in das TextView eintragen soll. wie macht man das

    Grüße
    Terht
     

    Anhänge:

  4. the_alien, 04.08.2011 #4
    the_alien

    the_alien Android-Lexikon

    Beiträge:
    1,559
    Erhaltene Danke:
    184
    Registriert seit:
    04.05.2009
    Geh in die Windows Konsole und rufe dort adb logcat auf und poste den Stacktrace.

    Eine ResourceID wird über android:id="" vergeben.
     
  5. Terth, 04.08.2011 #5
    Terth

    Terth Threadstarter Neuer Benutzer

    Beiträge:
    16
    Erhaltene Danke:
    0
    Registriert seit:
    04.08.2011
    W/PackageManager( 79): Code path for pkg : WorkflowApp.Activities changing fro
    m /data/app/WorkflowApp.Activities-1.apk to /data/app/WorkflowApp.Activities-2.a
    pk
    W/PackageManager( 79): Resource path for pkg : WorkflowApp.Activities changing
    from /data/app/WorkflowApp.Activities-1.apk to /data/app/WorkflowApp.Activities
    -2.apk
    D/PackageManager( 79): Activities: WorkflowApp.Activities.MainMenuActivity
    I/ActivityManager( 79): Force stopping package WorkflowApp.Activities uid=1003
    6
    D/PackageManager( 79): New package installed in /data/app/WorkflowApp.Activiti
    es-2.apk
    I/ActivityManager( 79): Force stopping package WorkflowApp.Activities uid=1003
    6
    D/dalvikvm( 79): GC_EXPLICIT freed 729K, 50% free 14562K/28615K, paused 11ms+1
    1ms
    D/PackageManager( 79): generateServicesMap(android.accounts.AccountAuthenticat
    or): 2 services unchanged
    D/PackageManager( 79): generateServicesMap(android.content.SyncAdapter): 4 ser
    vices unchanged
    D/dalvikvm( 195): GC_EXPLICIT freed 162K, 5% free 6826K/7175K, paused 4ms+4ms
    I/AccountTypeManager( 195): Loaded meta-data for 1 account types, 0 accounts in
    9ms
    D/PackageManager( 79): generateServicesMap(android.accounts.AccountAuthenticat
    or): 2 services unchanged
    D/PackageManager( 79): generateServicesMap(android.content.SyncAdapter): 4 ser
    vices unchanged
    I/AccountTypeManager( 195): Loaded meta-data for 1 account types, 0 accounts in
    12ms
    W/RecognitionManagerService( 79): no available voice recognition services foun
    d
    D/dalvikvm( 79): GC_EXPLICIT freed 441K, 50% free 14520K/28615K, paused 52ms+4
    1ms
    D/AndroidRuntime( 814): Shutting down VM
    D/dalvikvm( 814): GC_CONCURRENT freed 100K, 84% free 339K/2048K, paused 1ms+2ms

    I/AndroidRuntime( 814): NOTE: attach of thread 'Binder Thread #3' failed
    D/jdwp ( 814): Got wake-up signal, bailing out of select
    D/dalvikvm( 814): Debugger has detached; object registry had 1 entries
    D/AndroidRuntime( 828):
    D/AndroidRuntime( 828): >>>>>> AndroidRuntime START com.android.internal.os.Run
    timeInit <<<<<<
    D/AndroidRuntime( 828): CheckJNI is ON
    D/AndroidRuntime( 828): Calling main entry com.android.commands.am.Am
    I/ActivityManager( 79): Starting: Intent { act=android.intent.action.MAIN cat=
    [android.intent.category.LAUNCHER] flg=0x10000000 cmp=WorkflowApp.Activities/.Ma
    inMenuActivity } from pid 828
    W/WindowManager( 79): Failure taking screenshot for (230x135) to layer 21005
    I/ActivityManager( 79): Start proc WorkflowApp.Activities for activity Workflo
    wApp.Activities/.MainMenuActivity: pid=836 uid=10036 gids={}
    D/AndroidRuntime( 828): Shutting down VM
    I/AndroidRuntime( 828): NOTE: attach of thread 'Binder Thread #3' failed
    D/dalvikvm( 828): GC_CONCURRENT freed 101K, 83% free 366K/2048K, paused 1ms+1ms

    D/jdwp ( 828): Got wake-up signal, bailing out of select
    D/dalvikvm( 828): Debugger has detached; object registry had 1 entries
    D/dalvikvm( 836): GC_FOR_ALLOC freed 35K, 4% free 6387K/6595K, paused 162ms
    I/dalvikvm-heap( 836): Grow heap (frag case) to 6.784MB for 513744-byte allocat
    ion
    D/dalvikvm( 836): GC_FOR_ALLOC freed <1K, 4% free 6889K/7111K, paused 50ms
    D/dalvikvm( 836): GC_CONCURRENT freed <1K, 4% free 6889K/7111K, paused 5ms+2ms
    I/ActivityManager( 79): Displayed WorkflowApp.Activities/.MainMenuActivity: +2
    s604ms
    D/dalvikvm( 156): GC_EXPLICIT freed 1359K, 19% free 20432K/25031K, paused 284ms
    +4ms
    D/dalvikvm( 156): GC_CONCURRENT freed 2005K, 19% free 20407K/25031K, paused 16m
    s+27ms
    D/dalvikvm( 195): GC_EXPLICIT freed 162K, 5% free 6823K/7175K, paused 23ms+4ms
    D/AndroidRuntime( 847):
    D/AndroidRuntime( 847): >>>>>> AndroidRuntime START com.android.internal.os.Run
    timeInit <<<<<<
    D/AndroidRuntime( 847): CheckJNI is ON
    D/AndroidRuntime( 847): Calling main entry com.android.commands.pm.Pm
    D/dalvikvm( 261): GC_EXPLICIT freed 12K, 5% free 6303K/6595K, paused 5ms+3ms
    W/ActivityManager( 79): No content provider found for:
    W/ActivityManager( 79): No content provider found for:
    D/PackageParser( 79): Scanning package: /data/app/vmdl1357536222.tmp
    I/PackageManager( 79): Removing non-system package:WorkflowApp.Activities
    I/ActivityManager( 79): Force stopping package WorkflowApp.Activities uid=1003
    6
    I/Process ( 79): Sending signal. PID: 836 SIG: 9
    I/WindowManager( 79): WIN DEATH: Window{4091ca90 WorkflowApp.Activities/Workfl
    owApp.Activities.MainMenuActivity paused=false}
    D/PackageManager( 79): Scanning package WorkflowApp.Activities
    I/PackageManager( 79): Package WorkflowApp.Activities codePath changed from /d
    ata/app/WorkflowApp.Activities-2.apk to /data/app/WorkflowApp.Activities-1.apk;
    Retaining data and using new
    W/InputManagerService( 79): Got RemoteException sending setActive(false) notif
    ication to pid 836 uid 10036
    I/PackageManager( 79): Unpacking native libraries for /data/app/WorkflowApp.Ac
    tivities-1.apk
    D/dalvikvm( 856): DexOpt: load 46ms, verify+opt 135ms
    W/PackageManager( 79): Code path for pkg : WorkflowApp.Activities changing fro
    m /data/app/WorkflowApp.Activities-2.apk to /data/app/WorkflowApp.Activities-1.a
    pk
    W/PackageManager( 79): Resource path for pkg : WorkflowApp.Activities changing
    from /data/app/WorkflowApp.Activities-2.apk to /data/app/WorkflowApp.Activities
    -1.apk
    D/PackageManager( 79): Activities: WorkflowApp.Activities.MainMenuActivity
    I/ActivityManager( 79): Force stopping package WorkflowApp.Activities uid=1003
    6
    D/PackageManager( 79): New package installed in /data/app/WorkflowApp.Activiti
    es-1.apk
    D/dalvikvm( 156): GC_EXPLICIT freed 31K, 19% free 20378K/25031K, paused 7ms+8ms

    I/ActivityManager( 79): Force stopping package WorkflowApp.Activities uid=1003
    6
    D/dalvikvm( 79): GC_EXPLICIT freed 756K, 50% free 14576K/28615K, paused 7ms+8m
    s
    D/PackageManager( 79): generateServicesMap(android.accounts.AccountAuthenticat
    or): 2 services unchanged
    D/PackageManager( 79): generateServicesMap(android.content.SyncAdapter): 4 ser
    vices unchanged
    D/dalvikvm( 195): GC_EXPLICIT freed 12K, 6% free 6814K/7175K, paused 3ms+18ms
    I/AccountTypeManager( 195): Loaded meta-data for 1 account types, 0 accounts in
    9ms
    D/PackageManager( 79): generateServicesMap(android.accounts.AccountAuthenticat
    or): 2 services unchanged
    D/PackageManager( 79): generateServicesMap(android.content.SyncAdapter): 4 ser
    vices unchanged
    I/AccountTypeManager( 195): Loaded meta-data for 1 account types, 0 accounts in
    9ms
    W/RecognitionManagerService( 79): no available voice recognition services foun
    d
    D/dalvikvm( 79): GC_EXPLICIT freed 449K, 50% free 14528K/28615K, paused 41ms+3
    0ms
    D/AndroidRuntime( 847): Shutting down VM
    D/dalvikvm( 847): GC_CONCURRENT freed 100K, 84% free 339K/2048K, paused 1ms+1ms

    I/AndroidRuntime( 847): NOTE: attach of thread 'Binder Thread #3' failed
    D/jdwp ( 847): Got wake-up signal, bailing out of select
    D/dalvikvm( 847): Debugger has detached; object registry had 1 entries
    D/dalvikvm( 156): GC_FOR_ALLOC freed 1855K, 19% free 20434K/25031K, paused 125m
    s
    D/AndroidRuntime( 861):
    D/AndroidRuntime( 861): >>>>>> AndroidRuntime START com.android.internal.os.Run
    timeInit <<<<<<
    D/AndroidRuntime( 861): CheckJNI is ON
    D/AndroidRuntime( 861): Calling main entry com.android.commands.am.Am
    I/ActivityManager( 79): Starting: Intent { act=android.intent.action.MAIN cat=
    [android.intent.category.LAUNCHER] flg=0x10000000 cmp=WorkflowApp.Activities/.Ma
    inMenuActivity } from pid 861
    W/WindowManager( 79): Failure taking screenshot for (230x135) to layer 21005
    I/ActivityManager( 79): Start proc WorkflowApp.Activities for activity Workflo
    wApp.Activities/.MainMenuActivity: pid=869 uid=10036 gids={}
    D/AndroidRuntime( 861): Shutting down VM
    I/AndroidRuntime( 861): NOTE: attach of thread 'Binder Thread #3' failed
    D/dalvikvm( 861): GC_CONCURRENT freed 101K, 83% free 366K/2048K, paused 2ms+1ms

    D/dalvikvm( 861): Debugger has detached; object registry had 1 entries
    D/dalvikvm( 869): GC_FOR_ALLOC freed 36K, 4% free 6387K/6595K, paused 113ms
    I/dalvikvm-heap( 869): Grow heap (frag case) to 6.784MB for 513744-byte allocat
    ion
    D/dalvikvm( 869): GC_FOR_ALLOC freed <1K, 4% free 6889K/7111K, paused 56ms
    D/dalvikvm( 869): GC_CONCURRENT freed <1K, 4% free 6889K/7111K, paused 4ms+14ms

    I/ActivityManager( 79): Displayed WorkflowApp.Activities/.MainMenuActivity: +2
    s852ms
    D/dalvikvm( 156): GC_EXPLICIT freed 984K, 20% free 20205K/25031K, paused 14ms+8
    ms
    D/AndroidRuntime( 869): Shutting down VM
    W/dalvikvm( 869): threadid=1: thread exiting with uncaught exception (group=0x4
    0014760)
    E/AndroidRuntime( 869): FATAL EXCEPTION: main
    E/AndroidRuntime( 869): java.lang.NullPointerException
    E/AndroidRuntime( 869): at WorkflowApp.Activities.MainMenuActivity$1.onI
    temClick(MainMenuActivity.java:34)
    E/AndroidRuntime( 869): at android.widget.AdapterView.performItemClick(A
    dapterView.java:282)
    E/AndroidRuntime( 869): at android.widget.AbsListView.performItemClick(A
    bsListView.java:1037)
    E/AndroidRuntime( 869): at android.widget.AbsListView$PerformClick.run(A
    bsListView.java:2449)
    E/AndroidRuntime( 869): at android.widget.AbsListView$1.run(AbsListView.
    java:3073)
    E/AndroidRuntime( 869): at android.os.Handler.handleCallback(Handler.jav
    a:587)
    E/AndroidRuntime( 869): at android.os.Handler.dispatchMessage(Handler.ja
    va:92)
    E/AndroidRuntime( 869): at android.os.Looper.loop(Looper.java:132)
    E/AndroidRuntime( 869): at android.app.ActivityThread.main(ActivityThrea
    d.java:4123)
    E/AndroidRuntime( 869): at java.lang.reflect.Method.invokeNative(Native
    Method)
    E/AndroidRuntime( 869): at java.lang.reflect.Method.invoke(Method.java:4
    91)
    E/AndroidRuntime( 869): at com.android.internal.os.ZygoteInit$MethodAndA
    rgsCaller.run(ZygoteInit.java:841)
    E/AndroidRuntime( 869): at com.android.internal.os.ZygoteInit.main(Zygot
    eInit.java:599)
    E/AndroidRuntime( 869): at dalvik.system.NativeStart.main(Native Method)

    W/ActivityManager( 79): Force finishing activity WorkflowApp.Activities/.Mai
    nMenuActivity
    W/WindowManager( 79): Failure taking screenshot for (230x135) to layer 21010
    W/ActivityManager( 79): Activity pause timeout for ActivityRecord{407be8d8 Wor
    kflowApp.Activities/.MainMenuActivity}
    D/dalvikvm( 261): GC_EXPLICIT freed 10K, 5% free 6300K/6595K, paused 6ms+3ms
    W/ActivityManager( 79): Activity destroy timeout for ActivityRecord{407be8d8 W
    orkflowApp.Activities/.MainMenuActivity}
    D/dalvikvm( 315): GC_EXPLICIT freed 53K, 6% free 6379K/6727K, paused 5ms+7ms
    D/dalvikvm( 351): GC_EXPLICIT freed 26K, 5% free 6293K/6595K, paused 4ms+7ms
    D/AndroidRuntime( 881):
    D/AndroidRuntime( 881): >>>>>> AndroidRuntime START com.android.internal.os.Run
    timeInit <<<<<<
    D/AndroidRuntime( 881): CheckJNI is ON
    D/AndroidRuntime( 881): Calling main entry com.android.commands.pm.Pm
    D/dalvikvm( 261): GC_EXPLICIT freed 4K, 5% free 6301K/6595K, paused 6ms+7ms
    W/ActivityManager( 79): No content provider found for:
    W/ActivityManager( 79): No content provider found for:
    D/PackageParser( 79): Scanning package: /data/app/vmdl1465862436.tmp
    I/PackageManager( 79): Removing non-system package:WorkflowApp.Activities
    I/ActivityManager( 79): Force stopping package WorkflowApp.Activities uid=1003
    6
    I/Process ( 79): Sending signal. PID: 869 SIG: 9
    D/dalvikvm( 156): GC_EXPLICIT freed 1249K, 19% free 20381K/25031K, paused 52ms+
    5ms
    I/WindowManager( 79): WIN DEATH: Window{40989bd0 WorkflowApp.Activities/Workfl
    owApp.Activities.MainMenuActivity paused=false}
    D/PackageManager( 79): Scanning package WorkflowApp.Activities
    I/PackageManager( 79): Package WorkflowApp.Activities codePath changed from /d
    ata/app/WorkflowApp.Activities-1.apk to /data/app/WorkflowApp.Activities-2.apk;
    Retaining data and using new
    I/PackageManager( 79): Unpacking native libraries for /data/app/WorkflowApp.Ac
    tivities-2.apk
    D/dalvikvm( 890): DexOpt: load 50ms, verify+opt 149ms
    W/PackageManager( 79): Code path for pkg : WorkflowApp.Activities changing fro
    m /data/app/WorkflowApp.Activities-1.apk to /data/app/WorkflowApp.Activities-2.a
    pk
    W/PackageManager( 79): Resource path for pkg : WorkflowApp.Activities changing
    from /data/app/WorkflowApp.Activities-1.apk to /data/app/WorkflowApp.Activities
    -2.apk
    D/PackageManager( 79): Activities: WorkflowApp.Activities.MainMenuActivity
    I/ActivityManager( 79): Force stopping package WorkflowApp.Activities uid=1003
    6
    D/PackageManager( 79): New package installed in /data/app/WorkflowApp.Activiti
    es-2.apk
    I/ActivityManager( 79): Force stopping package WorkflowApp.Activities uid=1003
    6
    D/dalvikvm( 79): GC_EXPLICIT freed 796K, 49% free 14632K/28615K, paused 12ms+8
    ms
    D/PackageManager( 79): generateServicesMap(android.accounts.AccountAuthenticat
    or): 2 services unchanged
    D/PackageManager( 79): generateServicesMap(android.content.SyncAdapter): 4 ser
    vices unchanged
    D/dalvikvm( 195): GC_EXPLICIT freed 150K, 5% free 6826K/7175K, paused 4ms+4ms
    I/AccountTypeManager( 195): Loaded meta-data for 1 account types, 0 accounts in
    8ms
    D/PackageManager( 79): generateServicesMap(android.accounts.AccountAuthenticat
    or): 2 services unchanged
    D/PackageManager( 79): generateServicesMap(android.content.SyncAdapter): 4 ser
    vices unchanged
    W/RecognitionManagerService( 79): no available voice recognition services foun
    d
    I/AccountTypeManager( 195): Loaded meta-data for 1 account types, 0 accounts in
    12ms
    D/dalvikvm( 79): GC_EXPLICIT freed 460K, 50% free 14571K/28615K, paused 8ms+41
    ms
    D/AndroidRuntime( 881): Shutting down VM
    D/dalvikvm( 881): GC_CONCURRENT freed 100K, 84% free 339K/2048K, paused 1ms+1ms

    D/SntpClient( 79): request time failed: java.net.SocketException: Address fami
    ly not supported by protocol
    D/jdwp ( 881): Got wake-up signal, bailing out of select
    D/dalvikvm( 881): Debugger has detached; object registry had 1 entries
    I/AndroidRuntime( 881): NOTE: attach of thread 'Binder Thread #3' failed
    D/AndroidRuntime( 895):
    D/AndroidRuntime( 895): >>>>>> AndroidRuntime START com.android.internal.os.Run
    timeInit <<<<<<
    D/AndroidRuntime( 895): CheckJNI is ON
    D/AndroidRuntime( 895): Calling main entry com.android.commands.am.Am
    I/ActivityManager( 79): Starting: Intent { act=android.intent.action.MAIN cat=
    [android.intent.category.LAUNCHER] flg=0x10000000 cmp=WorkflowApp.Activities/.Ma
    inMenuActivity } from pid 895
    W/WindowManager( 79): Failure taking screenshot for (230x135) to layer 21005
    I/ActivityManager( 79): Start proc WorkflowApp.Activities for activity Workflo
    wApp.Activities/.MainMenuActivity: pid=903 uid=10036 gids={}
    D/AndroidRuntime( 895): Shutting down VM
    D/dalvikvm( 895): GC_CONCURRENT freed 101K, 83% free 366K/2048K, paused 1ms+1ms

    I/AndroidRuntime( 895): NOTE: attach of thread 'Binder Thread #3' failed
    D/jdwp ( 895): Got wake-up signal, bailing out of select
    D/dalvikvm( 895): Debugger has detached; object registry had 1 entries
    D/dalvikvm( 903): GC_FOR_ALLOC freed 37K, 4% free 6387K/6595K, paused 74ms
    I/dalvikvm-heap( 903): Grow heap (frag case) to 6.784MB for 513744-byte allocat
    ion
    D/dalvikvm( 903): GC_FOR_ALLOC freed <1K, 4% free 6889K/7111K, paused 67ms
    D/dalvikvm( 903): GC_CONCURRENT freed <1K, 4% free 6889K/7111K, paused 8ms+5ms
    D/dalvikvm( 79): GREF has increased to 501
    I/ActivityManager( 79): Displayed WorkflowApp.Activities/.MainMenuActivity: +2
    s680ms
    D/dalvikvm( 156): GC_EXPLICIT freed 1362K, 19% free 20432K/25031K, paused 4ms+5
    ms
    I/dalvikvm( 156): Jit: resizing JitTable from 512 to 1024
    D/dalvikvm( 156): GC_CONCURRENT freed 1594K, 17% free 20818K/25031K, paused 14m
    s+13ms
    D/dalvikvm( 195): GC_EXPLICIT freed 161K, 5% free 6823K/7175K, paused 17ms+4ms
    D/dalvikvm( 261): GC_EXPLICIT freed 8K, 5% free 6300K/6595K, paused 10ms+3ms
    D/SntpClient( 79): request time failed: java.net.SocketException: Address fami
    ly not supported by protocol


    ob das richtig ist das sieht anders aus als die eclipse logcat sorry bin neu
     
  6. Terth, 04.08.2011 #6
    Terth

    Terth Threadstarter Neuer Benutzer

    Beiträge:
    16
    Erhaltene Danke:
    0
    Registriert seit:
    04.08.2011
    Ich habs jetzt. Ich habe den Standard ArrayAdapter<String> benutzt. Dieser kann aber nur ein Control (TextView, Button etc.) verarbeiten. Deswegen muss man sich einen eigenen schreiben der in der getView Methode einen View aus mehreren Controls, in meinem Fall Image und TextView zurückgeben kann.

    SimpleArrayAdapter

    Code:
    import WorkflowApp.Activities.R;
    import android.app.Activity;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ArrayAdapter;
    import android.widget.TextView;
    
    public class SimpleArrayAdapter extends ArrayAdapter<String>
    {
        private final Activity m_Context;
        private final String[] m_aItemNames;
        
        public SimpleArrayAdapter(Activity context, String[] aItemNames)
        {
            super(context, R.layout.list_item, aItemNames);
            m_Context = context; 
            m_aItemNames = aItemNames;
        }
        
        public View getView(int iPosition, View convertView, ViewGroup parent)
        {
            LayoutInflater inflater = m_Context.getLayoutInflater();
            View rowView = inflater.inflate(R.layout.list_item, null, true);
            TextView textView = (TextView) rowView.findViewById(R.id.TextView_Name);
            textView.setText(m_aItemNames[iPosition]);
            return rowView;
        }
    }
    MainMenuActivity

    Code:
    public class MainMenuActivity extends ListActivity 
    {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            
            String[] aMenuItems = getResources().getStringArray(R.array.mainMenuItems);
            //nehme ein Standard Android list_item
            //setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, aMenuItems));
            //nehme das selbst geschriebene list_item
            SimpleArrayAdapter adapter = new SimpleArrayAdapter(this, aMenuItems);
            setListAdapter(adapter);
            
            ListView lv = getListView();
            lv.setTextFilterEnabled(true);
    
            lv.setOnItemClickListener(new OnItemClickListener() 
            {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
                {
                    // TODO Auto-generated method stub
                    //Zugriff auf den Text über das StandardAndroid layout
                    //String s = (String)((TextView)view.findViewById(android.R.id.text1)).getText();
                    //Zugriff über eigenes
                    String s = (String)((TextView)view.findViewById(R.id.TextView_Name)).getText();
                    Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
                }
            });
        }
    }
    ich schreib die Lösung hier mal für die Allgemeinheit

    liebe grüße
    Terth
     

Diese Seite empfehlen