我遇到問題。在列表視圖按鈕上執行不同的任務點擊
listview position 1
button1
listview position 2
button2
這是我設計的listview。我的適配器是遵循
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});
現在,我給我的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>
我porblem是定義我的XML按鈕,這是適配器和按鈕呼叫是隻定義我只是一次在XML中,我想執行不同的任務,每次點擊每個位置的listview.For我用
@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");
}
和以及我不能使用此
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
// When clicked, show a toast with the TextView text
}
});
那麼我怎麼會認識到它列表按鈕位置點擊執行不同的任務。
問題解決還是仍然面臨? –
@Chintan ..感謝好奇心在我的問題,,,我仍然是同樣的問題 – DJhon
你應該去選擇項目時從視圖搜索兒童。 –