- यदि आप केवल हनीकॉम्ब और ऊपर का समर्थन करते हैं, तो यह आसान होगा। एक स्टेटलिस्ट बनाएं और इसे आइटम की पृष्ठभूमि सूची में सेट करने के लिए सेट करें।
selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="@drawable/item_focus" />
<item android:drawable="@android:color/transparent" />
</selector>
सूचीदृश्य आइटम के लेआउट
<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="5dp" />
,210
और पिछले, SINGLE
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
2. करने के लिए अपने सूचीदृश्य विकल्प मोड सेट आप पूर्व मधुकोश समर्थन करने के लिए प्रबंधन करते हैं, आप अपने खुद के लेआउट चेक करने योग्य लागू लिखने के लिए होगा। चेक किए गए राज्य का उपयोग करके कार्य करने के लिए आप ऐसा करते हैं। लीनारलाउट के साथ एक उदाहरण लें (आप दूसरों के साथ भी ऐसा कर सकते हैं)।
package com.example.listviewactivestate;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Checkable;
import android.widget.LinearLayout;
public class CustomLinearLayout extends LinearLayout implements Checkable {
private static final int[] CHECKED_STATE_SET = { android.R.attr.state_checked };
private boolean checked = false;
public CustomLinearLayout (Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomLinearLayout (Context context) {
super(context);
}
@Override
public boolean isChecked() {
return checked;
}
@Override
public void setChecked(boolean checked) {
this.checked = checked;
refreshDrawableState();
// Propagate to childs
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child instanceof Checkable) {
((Checkable) child).setChecked(checked);
}
}
}
@Override
protected int[] onCreateDrawableState(int extraSpace) {
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
if (isChecked()) {
mergeDrawableStates(drawableState, CHECKED_STATE_SET);
}
return drawableState;
}
@Override
public void toggle() {
this.checked = !this.checked;
}
}
इस कस्टम SINGLE
को state_checked
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/item_focus" />
<item android:drawable="@android:color/transparent" />
</selector>
इसके अलावा सेट सूचीदृश्य विकल्प मोड के लिए एक्सएमएल
<?xml version="1.0" encoding="utf-8"?>
<com.example.listviewactivestate.CustomLinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/selector"
>
<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="5dp" />
</com.example.listviewactivestate.CustomLinearLayout >
बदलें state_activated
में दृश्य का उपयोग करें। यदि यह काम नहीं करता है, तो onItemClickEvent
इस
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
list.setItemChecked(position, true);//make sure click item is set to checked.
}
});
कृपया कुछ कोड या छवि जोड़ें। मेरे लिए समझना मुश्किल है। –
@Yul यह http://pastebin.com/3eeZ38dN – Harshid