![](/img/trans.png)
[英]“ViewPostImeInputStage processPointer 0” in log when item in RecyclerView is tapped?
[英]ViewRootImpl: ViewPostImeInputStage processPointer 0 on OnItemClick of Listview in android
我有一個像這樣的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>
和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);
}
});
}
我只想創建一個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,沒有任何顯示。
謝謝你寶貴的時間。
這個運行沒有問題所以也許你的適配器
@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點擊:點擊項目位置: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
您沒有列出Custom_Cart_Adapter.java。 嘗試在您在Custom_Cart_Adapter.java中使用的single_item.xml中添加android:focusable =“false”它可以提供幫助。
不應使用listview中的onItemClickListener,因為它可能導致許多問題。 對於這種情況,我建議在適配器的視圖上使用自定義單擊偵聽器,並通過此單擊偵聽器傳遞索引,我的意思是,嘗試實現自己的onItemClickListener。
您可能會注意到,在recyclerView上,onItemClickListener沒有出現,正確的方法是實現您自己的onItemClickListener。
你做得對,但對於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);
}
});
希望它能幫到你!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.