Activity
수업 코드 :
conversationList = (ListView)findViewById(android.R.id.list);
ConversationArrayAdapter conversationArrayAdapter=new ConversationArrayAdapter(this, R.layout.conversation_list_item_format_left, conversationDetails);
conversationList.setAdapter(conversationArrayAdapter);
conversationList.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Log.d("test","clicked");
}
});
클래스 의 getView
기능 Adapter
:
if (v == null) {
LayoutInflater vi = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(leftSideMessageNumber.equals(m.getTo())) {
v = vi.inflate(R.layout.conversation_list_item_format_left, null);
} else {
v = vi.inflate(R.layout.conversation_list_item_format_right, null);
}
}
팽창하는 동안 두 개의 XML을 사용하는 데 문제가 있습니까?
답변
방금 여기에서 해결책을 찾았지만 깊은 클릭으로.
목록의 행 항목에 포커스 가능하거나 클릭 가능한보기가 포함되어 있으면 OnItemClickListener
작동하지 않습니다.
행 항목은과 같은 매개 변수를 가져야합니다
android:descendantFocusability = "blocksDescendants"
.
여기에서 목록 항목이 어떻게 표시되는지 예를 볼 수 있습니다. 목록 항목 xml은 다음과 같아야합니다
row_item.xml
( your_xml_file.xml
).
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical" >
// your other widgets here
</LinearLayout>
답변
문제는 레이아웃에 포커스 가능하거나 클릭 가능한 항목이 포함되어 있다는 것입니다. 뷰에 포커스 가능하거나 클릭 가능한 항목이 포함되어 있으면 OnItemCLickListener가 호출되지 않습니다.
그렇지 않은 경우 레이아웃 xml 중 하나를 게시하십시오.
답변
내 목록의 경우 내 행에는 버튼과 같이 클릭 할 수있는 다른 항목이 있으므로 담요를 blocksDescendants
수행해도 작동하지 않습니다. 대신 버튼의 XML에 줄을 추가했습니다.
android:focusable="false"
이렇게하면 버튼이 행의 클릭을 차단하지 못하지만 여전히 버튼을 클릭 할 수 있습니다.
답변
listview_item.xml에서 2 단계를 수행해야합니다.
- 루트 레이아웃을 다음과 같이 설정하십시오.
android:descendantFocusability="blocksDescendants"
- 이 항목에서 포커스 가능하거나 클릭 가능한보기를 설정하십시오.
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
예제는 다음과 같습니다. listview_item.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="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center_vertical"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
<RadioButton
android:id="@+id/script_name_radio_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#000"
android:padding="5dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
/>
</LinearLayout>
답변
listview의 사용자 정의 행 레이아웃에서 버튼 태그 안에 아래 코드를 사용하십시오.
android:focusable="false"
android:clickable="false"
답변
나는 같은 문제가 있었고 실수로 실수로 설정 한 것을 보았습니다.
@Override
public boolean isEnabled(int position)
{
return false;
}
내 CustomListViewAdapter 클래스에서.
이것을 다음과 같이 변경하면 :
return true;
문제를 해결했습니다. 누군가가 같은 실수를 저지른 경우를 대비하여 …
답변
사용 안드로이드 : descendantFocusability를
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dip"
android:background="@color/light_green"
android:descendantFocusability="blocksDescendants" >
루트 레이아웃에서 위의 추가