我有一个listView
baseAdapter
我希望在我的活动中使用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>
这是我的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");
}
我在这里实施了onItemClickListener
这个代码在Lg手机上除了android 6.0.1之外到处都运行良好! 帮助!
答案 0 :(得分:0)
您没有使用itemclicklistener连接列表视图。如果您实现了整个类的接口,那么您应该这样做:
listview.setOnItemClicklistener(this);