简体   繁体   English

ViewRootImpl:ViewPostImeInputStage processPointer 0 on onItemClick of Listview in android

[英]ViewRootImpl: ViewPostImeInputStage processPointer 0 on OnItemClick of Listview in android

I have a cart_layout like this: 我有一个像这样的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>

And the java code for it in Cart.java : Cart.java的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);
        }
    });
}

I just want to make an OnItemClick event but everytime I tap the item, even when the listview.setOnItemClickListener is there or not, Logcat shows 我只想创建一个OnItemClick事件,但每次点击该项时,即使listview.setOnItemClickListener存在与否,Logcat显示

ViewRootImpl: ViewPostImeInputStage processPointer 0 ViewRootImpl:ViewPostImeInputStage processPointer 0

ViewRootImpl: ViewPostImeInputStage processPointer 1 ViewRootImpl:ViewPostImeInputStage processPointer 1

and nothing happens. 没有任何反应。

I also see a strange log like this, sometime it said "true" sometime it said "false": 我也看到这样一个奇怪的日志,有时它说“真”,有时它说“假”:

ActivityThread: updateVisibility : ActivityRecord{3308191 token=android.os.BinderProxy@c7ed098 {com.iwant.namhhgames.newiwant/com.iwant.namhhgames.newiwant.Listing_items}} show : false ActivityThread:updateVisibility:ActivityRecord {3308191 token=android.os.BinderProxy@c7ed098 {com.iwant.namhhgames.newiwant / com.iwant.namhhgames.newiwant.Listing_items}} show:false

I don't know if it related to the problem, and I have no idea when the problem occurs, maybe after I messed something up. 我不知道它是否与问题有关,我不知道问题何时发生,也许是在我搞砸了之后。

And the Logcat is shown for real device only. Logcat只显示真实设备。 With AVD, there is nothing shown. 有了AVD,没有任何显示。

Thank you for your valuable time. 谢谢你宝贵的时间。

this run without issue so maybe your adapter 这个运行没有问题所以也许你的适配器

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.testlist);

        ListView listview = (ListView)findViewById(R.id.listest);

        ArrayList<String> cart_adapter = new ArrayList<String>();

        cart_adapter.add("Me");
        cart_adapter.add("Him");
        cart_adapter.add("You");

        listview.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,cart_adapter));

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.e("ITEM CLICK","CLICKED ITEM POSITION: "+position);
            }
        });

    }

11-16 14:55:31.735 1915-1915/ca.dti.grounded.app E/ITEM CLICK: CLICKED ITEM POSITION: 2 11-16 14:55:34.233 1915-1915/ca.dti.grounded.app E/ITEM CLICK: CLICKED ITEM POSITION: 0 11-16 14:55:35.616 1915-1915/ca.dti.grounded.app E/ITEM CLICK: CLICKED ITEM POSITION: 1 11-16 14:55:36.061 1915-1915/ca.dti.grounded.app E/ITEM CLICK: CLICKED ITEM POSITION: 2 11-16 14:55:31.735 1915-1915 / ca.dti.grounded.app E / ITEM点击:点击项目位置:2 11-16 14:55:34.233 1915-1915 / ca.dti.grounded.app E /项目点击:点击项目位置:0 11-16 14:55:35.616 1915-1915 / ca.dti.grounded.app E / ITEM点击:点击项目位置:1 11-16 14:55:36.061 1915-1915 / ca .dti.grounded.app E / ITEM点击:点击项目位置:2

You don't list Custom_Cart_Adapter.java. 您没有列出Custom_Cart_Adapter.java。 Try to add android:focusable="false" in your single_item.xml which you use inside Custom_Cart_Adapter.java It can help. 尝试在您在Custom_Cart_Adapter.java中使用的single_item.xml中添加android:focusable =“false”它可以提供帮助。

The onItemClickListener from listview should not be used as it can cause many issues as this. 不应使用listview中的onItemClickListener,因为它可能导致许多问题。 For this case, I would suggest the use of a custom click listener on the adapter's view and passing the index through this click listener, I mean, try to implement your own onItemClickListener. 对于这种情况,我建议在适配器的视图上使用自定义单击侦听器,并通过此单击侦听器传递索引,我的意思是,尝试实现自己的onItemClickListener。

As you may notice, at recyclerView the onItemClickListener doesn't appear and the proper approach is to implement your own onItemClickListener. 您可能会注意到,在recyclerView上,onItemClickListener没有出现,正确的方法是实现您自己的onItemClickListener。

You did right but for arrayadapter your onItemClick() listener should be look like this. 你做得对,但对于arrayadapter你的onItemClick()监听器应该是这样的。

ListView listview = (ListView)findViewById(R.id.listest);
   listview .setOnItemClickListener(new OnItemClickListener()
   {
      @Override
      public void onItemClick(AdapterView<?> adapter, View v, int position,
            long arg3) 
      {
            Log.e("ITEM CLICK","CLICKED ITEM POSITION: "+position);
      }
   });

Hope it will help you!! 希望它能帮到你!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM