简体   繁体   English

setOnItemClickListener在android 6.0.1中不起作用

[英]setOnItemClickListener not working in android 6.0.1

I have a listView with baseAdapter and I want to use set onItemClickListener in my activity and that works good in most of the phones except LG's phones with android 6.0.1? 我有一个带有baseAdapterlistView ,并且我想在我的活动中使用set onItemClickListener ,它在大多数手机中都能很好地工作,除了LG的Android 6.0.1手机外?

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    android:layout_marginLeft="120dp"
    >

    <ImageView
        android:id="@+id/image_country"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/india"
        android:padding="10dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="5dp"
        android:textSize="18dp"
        android:text="India"
        android:clickable="false"
        android:layout_weight="1"
        android:textColor="@color/black"
        android:id="@+id/text_country"/>

</LinearLayout>

This is my listview code snippet 这是我的listview代码段

languagesListAdapter = new LanguagesListAdapter(getApplicationContext(), prepareDataCountryList());
    listView.setAdapter(languagesListAdapter);

       @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Drawable drawable = getResources().getDrawable(languagesListAdapter.languagesToTranslates.get(position).getImagges());


    linearLayoutselectLanguageToTranslate.setVisibility(View.GONE);
    mInputView.setVisibility(View.VISIBLE);
    constraintLayoutBellowKeyboard.setVisibility(View.VISIBLE);
    Toast.makeText(getApplicationContext(), "Your text will be translated in " +
            languagesListAdapter.languagesToTranslates.get(position).getLanguae(), Toast.LENGTH_SHORT).show();
    PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("languageToTranslatInstantText",
            languagesListAdapter.languagesToTranslates.get(position).getCodeCountry()).apply();
    languageToTranslate = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("languageToTranslatInstantText", "en");

}

Here I implemented onItemClickListener 在这里我实现了onItemClickListener

This code is working good everywhere except android 6.0.1 on Lg phone!! 除了Lg手机上的android 6.0.1以外,这段代码在所有地方都正常工作! Help!! 救命!!

You didn't hookup your list view with the itemclicklistener. 您没有使用itemclicklistener连接列表视图。 If you implemented the interface to the whole class, you should do this: 如果您实现了整个类的接口,则应执行以下操作:

listview.setOnItemClicklistener(this);

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

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