我彼此有2个TwoWayView。内部是TWB,外部是TWA。
问题是TWA需要是可点击的,但onitemclick功能只能在onitemlongclick事件中运行。
TWA的持有人xml:
<RelativeLayout
android:layout_width="200dp"
android:layout_height="match_parent"
>
<org.lucasr.twowayview.TwoWayView
android:id="@+id/innerView"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
在TWA的适配器中,我试图禁用所有可点击和可聚焦的东西到TWB:
viewHolder.innerView.setAdapter(innerListAdapters.get(position));
viewHolder.innerView.setClickable(false);
viewHolder.innerView.setLongClickable(false);
viewHolder.innerView.setFocusable(false);
viewHolder.innerView.setItemsCanFocus(false);
viewHolder.innerView.setOnItemClickListener(null);
viewHolder.innerView.setOnItemLongClickListener(null);
viewHolder.innerView.setOnTouchListener(null);
viewHolder.innerView.setChoiceMode(TwoWayView.ChoiceMode.NONE);
viewHolder.innerView.setFocusableInTouchMode(false);
这就是我尝试将onItemClick和onItemLongClick设置为TWA的方式:
friendList.setAdapter(new FriendsAdapter(getActivity(), friends));
friendList.setLongClickable(true);
friendList.setClickable(true);
friendList.setItemMargin(10);
//final FriendsAdapter adapter = (FriendsAdapter) friendList.getAdapter();
friendList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
utils.sendToLog("l " + l + "");
friendListItemClicked(i);
}
});
friendList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
friendListItemLongClicked(i);
return true;
}
});
有人可以帮我吗?
答案 0 :(得分:0)
我做到了:)
问题是innerView发出了onClick事件。所以我不得不将我正常的onItemClick绑定到内部。就像在TWB中模拟TWA的项目一样。
这是未来的代码:)
viewHolder.innerView.setDescendantFocusability(RelativeLayout.FOCUS_BLOCK_DESCENDANTS);
{
final AdapterView fParent = (AdapterView) parent;
final View fView = rowView;
final int fInt = position;
final long fLong = rowView.getId();
AdapterView.OnItemClickListener cross = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
listener.onItemClick(fParent,fView, fInt, fLong);
}
};
viewHolder.innerView.setOnItemClickListener(cross);
}