커스텀 리스트 Android의 아이템에 대한 클릭 문제 표시
커스텀 ListView오브젝트가 있어요목록 항목에는 두 개의 텍스트 뷰가 겹쳐져 있고, 실제로 작업을 수행할 때까지 숨겨두려는 수평 진행 표시줄이 있습니다.오른쪽 끝에 있는 체크박스는 사용자가 업데이트를 데이터베이스에 다운로드해야 할 때만 표시합니다.가시성을 가시성으로 설정하여 확인란을 비활성화한 경우.GONE, 목록 항목을 클릭할 수 있습니다.체크박스가 뜨면 리스트의 체크박스를 제외한 아무것도 클릭할 수 없습니다.몇 가지 검색을 해봤지만 현재 상황과 관련된 것은 찾지 못했습니다.이 질문을 찾았는데 ArrayLists를 사용하여 데이터베이스 목록을 내부적으로 저장하기 때문에 덮어쓰기된 ArrayAdapter를 사용하고 있습니다.Tom처럼 Linear Layout 뷰를 가져와 on Click Listener를 추가하면 되나요?잘 모르겠어요.
listview 행 레이아웃 XML은 다음과 같습니다.
<?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
}
edit: 아직 이 문제가 발생하고 있습니다.텍스트 뷰에 onClick 핸들러를 추가하고 있는데 체크박스를 클릭하지 않았는데 onListItemClick() 함수가 전혀 호출되지 않는 것은 매우 어리석은 일입니다.
문제는 안드로이드가 초점을 맞출 수 있는 요소가 있는 목록 항목을 선택할 수 없다는 것입니다.목록 항목의 체크박스를 다음과 같은 속성을 가지도록 수정했습니다.
android:focusable="false"
기존의 의미에서는 체크박스를 포함한 리스트 아이템(버튼도 기능)이 「선택 가능」하게 되었습니다(라이트 표시, 리스트 아이템의 임의의 장소를 클릭할 수 있어 「onListItemClick」핸들러가 기동하는 등).
편집: 코멘트는 업데이트로 "단순히 메모로 버튼의 가시성을 변경한 후 다시 포커스를 프로그래밍 방식으로 비활성화해야 했습니다."라고 언급했습니다.
목록 항목 내에 ImageButton이 있는 경우,descendantFocusability
값을 루트 목록 항목 요소의 'blockDescendants'로 지정합니다.
android:descendantFocusability="blocksDescendants"
그리고 그focusableInTouchMode
에 깃발을 올리다.true
에서ImageButton
syslogda를 클릭합니다.
android:focusableInTouchMode="true"
비슷한 문제가 발생한 적이 있는데 ListView에서 CheckBox가 다소 까다롭다는 것을 알게 되었습니다.그러면 ListItem 전체에 will이 적용되어 onListItemClick이 덮어쓰게 됩니다.이를 위해 클릭 핸들러를 구현하고 TextViews를 사용하는 대신 CheckBox의 텍스트 속성을 설정할 수도 있습니다.
이 View 객체도 CheckBox보다 더 잘 작동할 수 있습니다.
목록 항목의 루트 보기에서 이 줄을 사용합니다.
Android:descendantFocusability="blocksDescendants"
언급URL : https://stackoverflow.com/questions/1121192/custom-listview-click-issue-on-items-in-android
'programing' 카테고리의 다른 글
MySQL에서 두 데이터 시간 간의 차이 계산 (0) | 2023.01.24 |
---|---|
JavaScript에서 큰 숫자에 대한 과학적 표기법을 피하는 방법은 무엇입니까? (0) | 2023.01.24 |
Selenium - 페이지가 완전히 로드될 때까지 기다리는 방법 (0) | 2023.01.14 |
Python에서 '@=' 기호는 무엇입니까? (0) | 2023.01.14 |
Java에서 늘과 문자열을 대조하는 방법은 무엇입니까? (0) | 2023.01.14 |