पर क्लिक करने में असमर्थ हैं इसलिए मेरे पास एक कस्टम ListView ऑब्जेक्ट है। सूची वस्तुओं में एक दूसरे के शीर्ष पर दो पाठदृश्य होते हैं, साथ ही एक क्षैतिज प्रगति पट्टी जिसे मैं छिपाना चाहता हूं जब तक कि मैं वास्तव में कुछ नहीं करता। बहुत दूर तक एक चेकबॉक्स है जिसे मैं केवल तब प्रदर्शित करना चाहता हूं जब उपयोगकर्ता को अपने डेटाबेस में अपडेट डाउनलोड करने की आवश्यकता हो। जब मैं दृश्यता के लिए दृश्यता सेट करके चेकबॉक्स अक्षम करता हूं। तो, मैं सूची आइटम पर क्लिक करने में सक्षम हूं। जब चेकबॉक्स दिखाई देता है, तो मैं चेकबॉक्स को छोड़कर सूची में किसी भी चीज़ पर क्लिक करने में असमर्थ हूं। मैंने कुछ खोज की है लेकिन मेरी वर्तमान स्थिति के लिए कुछ भी प्रासंगिक नहीं मिला है। मुझे this question मिला लेकिन मैं एक ओवरराइड किया गया ArrayAdapter का उपयोग कर रहा हूं क्योंकि मैं आंतरिक रूप से डेटाबेस की सूची रखने के लिए ArrayLists का उपयोग कर रहा हूं। क्या मुझे लाइनरलाइट दृश्य प्राप्त करने की आवश्यकता है और टॉम की तरह ऑनक्लिक लिस्टनर जोड़ना है? मुझे यकीन नहीं है।एंड्रॉइड कस्टम लिस्ट व्यू
यहाँ सूचीदृश्य पंक्ति लेआउट एक्सएमएल है:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:id="@+id/UpdateNameText"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:textSize="18sp"
android:gravity="center_vertical"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="@+id/UpdateStatusText"
android:singleLine="true"
android:ellipsize="marquee"
/>
<ProgressBar android:id="@+id/UpdateProgress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminateOnly="false"
android:progressDrawable="@android:drawable/progress_horizontal"
android:indeterminateDrawable="@android:drawable/progress_indeterminate_horizontal"
android:minHeight="10dip"
android:maxHeight="10dip"
/>
</LinearLayout>
<CheckBox android:text=""
android:id="@+id/UpdateCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
और यहाँ वर्ग कि ListActivity फैली है।
public class UpdateActivity extends ListActivity {
AccountManager lookupDb;
boolean allSelected;
UpdateListAdapter list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lookupDb = new AccountManager(this);
lookupDb.loadUpdates();
setContentView(R.layout.update);
allSelected = false;
list = new UpdateListAdapter(this, R.layout.update_row, lookupDb.getUpdateItems());
setListAdapter(list);
Button btnEnterRegCode = (Button)findViewById(R.id.btnUpdateRegister);
btnEnterRegCode.setVisibility(View.GONE);
Button btnSelectAll = (Button)findViewById(R.id.btnSelectAll);
btnSelectAll.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
allSelected = !allSelected;
for(int i=0; i < lookupDb.getUpdateItems().size(); i++) {
lookupDb.getUpdateItem(i).setSelected(!lookupDb.getUpdateItem(i).isSelected());
}
list.notifyDataSetChanged();
// loop through each UpdateItem and set the selected attribute to the inverse
} // end onClick
}); // end setOnClickListener
Button btnUpdate = (Button)findViewById(R.id.btnUpdate);
btnUpdate.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
} // end onClick
}); // end setOnClickListener
lookupDb.close();
} // end onCreate
@Override
protected void onDestroy() {
super.onDestroy();
for (UpdateItem item : lookupDb.getUpdateItems()) {
item.getDatabase().close();
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
UpdateItem item = lookupDb.getUpdateItem(position);
if (item != null) {
item.setSelected(!item.isSelected());
list.notifyDataSetChanged();
}
}
private class UpdateListAdapter extends ArrayAdapter<UpdateItem> {
private List<UpdateItem> items;
public UpdateListAdapter(Context context, int textViewResourceId, List<UpdateItem> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = null;
if (convertView == null) {
LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = li.inflate(R.layout.update_row, null);
} else {
row = convertView;
}
UpdateItem item = items.get(position);
if (item != null) {
TextView upper = (TextView)row.findViewById(R.id.UpdateNameText);
TextView lower = (TextView)row.findViewById(R.id.UpdateStatusText);
CheckBox cb = (CheckBox)row.findViewById(R.id.UpdateCheckBox);
upper.setText(item.getName());
lower.setText(item.getStatusText());
if (item.getStatusCode() == UpdateItem.UP_TO_DATE) {
cb.setVisibility(View.GONE);
} else {
cb.setVisibility(View.VISIBLE);
cb.setChecked(item.isSelected());
}
ProgressBar pb = (ProgressBar)row.findViewById(R.id.UpdateProgress);
pb.setVisibility(View.GONE);
}
return row;
}
} // end inner class UpdateListAdapter
}
संपादित करें: जाहिर है यह बहुत चीजें हैं जो याद कर रहे हैं या आसपास बिछाने छोड़ दिया हो सकता है माफ कर विकास में अभी भी मैं अभी भी इस समस्या आ रही है। मैं धोखाधड़ी कर रहा हूं और टेक्स्टव्यू पर क्लिक हैंडलर जोड़ रहा हूं लेकिन यह बेहद बेवकूफ लगता है कि जब मैं अपने चेकबॉक्स पर क्लिक नहीं कर रहा हूं तो मेरा onListItemClick() फ़ंक्शन बिल्कुल नहीं कहा जा रहा है।
अरे मैट - निष्पक्ष होना करने के रूप में एक स्वीकार किए जाते हैं आप अपने जवाब को चिह्नित करना चाहिए :) यह आप 2 अंक खर्च होंगे तो यह ऑफसेट करने के लिए मैं आपका जवाब – Bostone
upmarked मैं इस सवाल का जवाब मैं चयनित पूर्ववत करने के लिए एक विकल्प नहीं दिख रहा। और मैं वास्तव में लड़के से दूर अंक नहीं लेना चाहता हूं। : डी – MattC
पूर्ववत करने के लिए फिर से हरे रंग की जांच पर क्लिक करें। और कृपया ऐसा करें क्योंकि SO शीर्ष पर सबसे अच्छा/सही उत्तर रखने के बारे में है। –