ListView in Android-handler für das klicken auf Element

Ich habe eine activity in Android verwendet ein ListView. Wenn ich auf ein Element in der ListView, ich möchte in der Lage sein, zu bestimmen, welches Element geklickt wurde. Ich habe den folgenden code:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    setContentView(R.layout.listr);

   //setupDB();  
   //populateList3();
   ListView lv = (ListView) findViewById(R.id.ListView01);
   lv.setClickable(true);

   lv.setOnItemClickListener(new OnItemClickListener() {

   public void onItemClick(AdapterView<?> parent, View view, int position, long id) {      
        Toast.makeText(ListRecords.this,"Clicked!", Toast.LENGTH_LONG).show();
       }
   });

}

Meine layout.xml:

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout  
    xmlns:android="http://schemas.android.com/apk/res/android"  

     android:id="@+id/Linear03lr"
     android:layout_width="fill_parent"  
     android:orientation="vertical"  
     android:gravity="center"
     android:layout_height="fill_parent">  


 <!--Put form controls here-->  
    <ListView android:id="@+id/ListView01"

 android:layout_width="wrap_content"
 android:layout_height="400dp" />

     <Button
        android:id="@+id/previousbutton"
        android:gravity="center_horizontal"
        android:layout_width = "fill_parent"
        android:layout_height = "fill_parent"

        android:text="Previous Menu"/>
</LinearLayout>  

Was bin ich hier, um der Lage sein, um Sie abzufangen Klicks auf die Listview?

  • Wie kann ich akzeptieren, Antworten?
InformationsquelleAutor eljainc | 2011-02-18
Schreibe einen Kommentar