2016-03-28 11 views
0

Dies ist mein Code in der HaupttätigkeitListActivity Fehler: „Leider Ihre App gestoppt“

public class MainActivity extends ListActivity { 

    private String [] mainScreenList = {"Portal","Settings","Help","About"}; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     ArrayAdapter<String> mainScreen = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_activated_1, android.R.id.text1,mainScreenList); 
     ListView lv = (ListView) findViewById(R.id.listView); 
     lv.setAdapter(mainScreen); 
    } 
    @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) { 
     super.onListItemClick(l, v, position, id); 
     Object o = this.getListAdapter().getItem(position); 
     String pen = o.toString(); 
     Toast.makeText(this, "You have chosen the pen: " + " " + pen, Toast.LENGTH_LONG).show(); 
     //get selected items 
     /* if(position==0) 
     { 
      Intent i = new Intent(this, DataEntryActivity.class); 
      startActivity(i); 
     }else if(position==1) 
     { 
      Intent i = new Intent(this, DataEntryActivity.class); 
      startActivity(i); 
     }else if(position==2) 
     { 
      Intent i = new Intent(this, DataEntryActivity.class); 
      startActivity(i); 
     }else if(position==3) 
     { 
      Intent i = new Intent(this, DataEntryActivity.class); 
      startActivity(i); 
     }*/ 
    } 
} 

Im Moment habe ich nur versuche, den Namen der Listenansicht Artikel zu zeigen, ausgewählt.

Dies ist der XML-Code

<?xml version="1.0" encoding="utf-8"?> 
<ListView 
    android:id="@android:id/list" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context="com.example.bernine.practicalsessions.MainActivity"> 
    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/listView" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" 

     /> 
</ListView> 

Wenn die App läuft sie sagt: "Leider ist die App zum Stillstand gekommen ist."

+0

Beitrag Fehlerprotokoll .. –

+0

benötigen Fehlerprotokoll .. – Mohan

+1

Listview innerhalb Listview .. ???? – Dinash

Antwort

0

Einmal die activity_main.xml Layout-Datei auschecken. Sie haben ListView in einem anderen ListView eingeschlossen. das ist nicht gültig.

enthalten ListView in einem Container wie LinearLayout ,RelativeLayout , etc. Und für ListView sollten Sie ID wie @android:id/list verwenden. einmal dieses Beispiel Layout auschecken.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <ListView 
      android:id="@android:id/list" 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent"> 
     </ListView> 

    </LinearLayout> 
+0

akzeptieren, wenn es funktioniert. :) – shobhan

+0

Danke Ich habe es so angeordnet, wie Sie es mit Linear Layout erwähnt haben, und die ID in den ListView Container gestellt. In der MainActivity.java in dieser Codezeile ListView lv = (ListView) findViewById (R.id.list); - 'kann die Symbolliste nicht auflösen' – cgeekmt

+1

Verwenden Sie ListView lv = (ListView) findViewById (android.R.id.list); – shobhan

Verwandte Themen