gpt4 book ai didi

android - Listview 点击监听器没有响应

转载 作者:行者123 更新时间:2023-11-30 02:50:07 25 4
gpt4 key购买 nike

我有一个 ListView ,想对其执行可点击事件。我以前做过。但现在它不起作用。我也添加了我的 XML。我只需要在 ListView 中点击从一个 Activity 转移到另一个 Activity 。

      CustomFinalSubmit_ItemDetail item = new  CustomFinalSubmit_ItemDetail(Final_Submit.this , R.layout.customview_finalsubmit_itemdetails, itemInfo);
itemList.setAdapter(item);
itemList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
FinalSubmitItem pos = itemInfo.get(position);
String itemType = pos.getItemType();
String itemCountry = pos.getItemCountry();
String itemSerial = pos.getItemNo();
pos.setChecked(true);

Intent inn = new Intent(getApplicationContext(), FinalSubmitDetails.class);
inn.putExtra("itemType", itemType);
inn.putExtra("itemCountry", itemCountry);
inn.putExtra("itemSerial", itemSerial);
startActivity(inn);
}

});

这是我的主要 Xml:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/green">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill"
android:layout_marginTop="10dip"
android:orientation="vertical"
android:background="#0B3B0B">
<ListView
android:id="@+id/CustomerDetailList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/yellow"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:id="@+id/Itemtype"
android:paddingTop="5dp"
android:background="@color/green"
android:textColor="@color/yellow"
android:layout_marginLeft="5dip"
android:text="Item Type"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:paddingTop="5dp"
android:id="@+id/txtcountry"
android:background="@color/green"
android:textColor="@color/yellow"
android:text="Country"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:paddingTop="5dp"
android:id="@+id/txtItemNumber"
android:background="@color/green"
android:textColor="@color/yellow"
android:text="Item No."/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:id="@+id/itemChck"
android:button="@drawable/custom_checkbox"
android:paddingTop="5dp"
android:padding="5dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_margin="5dp"
android:layout_height="1dp"
android:background="@color/white"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/itemList"
android:background="#088A08"
android:divider="@color/white"
android:dividerHeight="1dp"/>
</LinearLayout>

</LinearLayout>
</LinearLayout>

最佳答案

我是这样做的:

            convertView.setOnClickListener(new View.OnClickListener() {                 
@Override
public void onClick(View v) {
your code
}});

只需将这么多代码添加到我的自定义 View

关于android - Listview 点击监听器没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24349077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com