J'ai un problème.effectuer une tâche différente sur le bouton listview cliquez sur
listview position 1
button1
listview position 2
button2
Ceci est mon design de liste. Mon adaptateur est le suivant
adapter = new SimpleCursorAdapter(this, R.layout.appareal_listview_text ,cursor, new String[]{"Key_ProductName","Key_SellingPrice"} , new int[] {R.id.title_info_txt_v,R.id.description_info_txt_v});
Maintenant, je donne mon fichier xml appareal_listview_text.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="@drawable/layout1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/title_info_txt_v"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:textColor="#000000"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="@+id/description_info_txt_v"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:layout_marginTop="4dip"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold" />
<Button
android:id="@+id/btnBuyNow_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="15dp"
android:background="@drawable/buynow"
android:clickable="true"
android:onClick="buynowClick" />
</LinearLayout>
Maintenant, mon porblem est mon bouton qui définissent en XML qui est appel par l'adaptateur et le bouton est défini seulement je une fois en xml, et je veux effectuer une tâche différente sur chaque clic de chaque position de listview.Pour cela j'ai utilisé
@Override
public void onListItemClick(ListView parent, View view, int position,
long id) {
Intent intent = new Intent(this, asasdad.class);
Cursor cursor = (Cursor) adapter.getItem(position);
intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
startActivity(intent);
System.out.println("list is click");
}
et ainsi que je ne peux pas utiliser ce
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
// When clicked, show a toast with the TextView text
}
});
Alors, comment je vais reconnaître quelle position bouton liste est cliqué pour effectuer des tâches différentes.
problème résolu ou toujours face? –
@Chintan ..Merci pour la curiosité dans mon problème ,,, je suis toujours le même problème – DJhon
Vous devriez aller chercher des enfants de vue lorsque l'élément est sélectionné. –