Tra*_*Nam 40 java android listview onitemclicklistener
我cart_layout喜欢这样的:
<?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:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:id="@+id/cart_listview"
android:layout_gravity="center_horizontal"
android:background="@color/whiteBg"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="bottom"
android:padding="5dp"
android:gravity="bottom"
android:background="@color/whiteBg">
<!-- this layout contains a button and a textview which I don't think is the problem -->
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
以及它的java代码Cart.java:
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cart_layout);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
dbhandler = new DatabaseHandler(this);
product_all = dbhandler.getProduct();
total = (TextView)findViewById(R.id.cart_total_textview);
listview = (ListView)findViewById(R.id.cart_listview);
cart_adapter = new Custom_Cart_Adapter(this,product_all);
listview.setAdapter(cart_adapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.v("ITEM CLICK","CLICKED ITEM POSITION: "+position);
Intent intent = new Intent(Cart.this, Item_edit_details.class);
intent.putExtra("the_product", product_all.get(position));
startActivity(intent);
}
});
}
Run Code Online (Sandbox Code Playgroud)
我只是想创建一个OnItemClick事件,但每次点击该项目时,即使listview.setOnItemClickListener存在与否,Logcat显示
ViewRootImpl:ViewPostImeInputStage processPointer 0
ViewRootImpl:ViewPostImeInputStage processPointer 1
没有任何反应.
我也看到这样一个奇怪的日志,有时它说"真",有时它说"假":
ActivityThread:updateVisibility:ActivityRecord {3308191 token=android.os.BinderProxy@c7ed098 {com.iwant.namhhgames.newiwant/com.iwant.namhhgames.newiwant.Listing_items}} show:false
我不知道它是否与问题有关,我不知道问题何时发生,也许是在我搞砸了之后.
Logcat只显示真实设备.有了AVD,没有任何显示.
谢谢你宝贵的时间.
小智 1
运行没有问题所以也许你的适配器
\n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n\n setContentView(R.layout.testlist);\n\n ListView listview = (ListView)findViewById(R.id.listest);\n\n ArrayList<String> cart_adapter = new ArrayList<String>();\n\n cart_adapter.add("Me");\n cart_adapter.add("Him");\n cart_adapter.add("You");\n\n listview.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,cart_adapter));\n\n listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {\n @Override\n public void onItemClick(AdapterView<?> parent, View view, int position, long id) {\n Log.e("ITEM CLICK","CLICKED ITEM POSITION: "+position);\n }\n });\n\n }\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n11-16 14:55:31.735 1915-1915/ca.dti.grounded.app E/ITEM\xc2\xa0CLICK:单击的项目位置:2\n 11-16 14:55:34.233 1915-1915/ca.dti。 grounded.app E/ITEM\xc2\xa0CLICK:单击的项目位置:0\n 11-16 14:55:35.616 1915-1915/ca.dti.grounded.app E/ITEM\xc2\xa0CLICK:单击的项目位置:1 \n 11-16 14:55:36.061 1915-1915/ca.dti.grounded.app E/ITEM\xc2\xa0CLICK:单击的项目位置:2
\n