我使用this作为滑动来删除。但我在实现列表的删除菜单项时遇到问题。
我正在做的只是创建一个删除项目。我真的不想使用任何其他项目,如Open,如演示中所示。
这是我的设计
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dadada">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/segmented_buttons">
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:orientation="vertical">
<!--<ScrollView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_gravity="center"-->
<!--android:gravity="center"-->
<!--android:clickable="false">-->
<TextView
android:id="@+id/swipeRefreshLayout_emptyView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|center_vertical"
android:enabled="false"
android:gravity="center"
android:visibility="gone" />
<com.baoyz.swipemenulistview.SwipeMenuListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:clipChildren="false"
android:divider="@android:color/transparent"
android:dividerHeight="5.0sp" />
<!--</ScrollView>-->
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
</RelativeLayout>
以下是我如何在片段中创建菜单
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu) {
// create "delete" item
SwipeMenuItem deleteItem = new SwipeMenuItem(
getActivity());
// set item background
deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9,
0x3F, 0x25)));
// set item width
deleteItem.setWidth(dp2px(90));
// set a icon
deleteItem.setIcon(R.drawable.ic_delete);
// add to menu
menu.addMenuItem(deleteItem);
}
};
这是我如何设置创建者
// set creator
mListView.setMenuCreator(creator);
我的问题我提到了有关删除的几个问题,如上所述
可能有什么问题?有什么猜测?有什么工作吗?
是的,确实如此,当我触摸删除菜单时,它会给我一个日志,向下看,它在日志中显示我,当我触摸删除和删除实际上不起作用,但是当它在日志中开始处理此消息从不显示。
D / ViewRootImpl:ViewPostImeInputStage ACTION_DOWN
编辑一个
这是我的整个适配器代码:
public class SwipeListOfferAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private ArrayList<OfferStatusData> offerList;
OfferStatusData offerStatusData;
public SwipeListOfferAdapter(Activity activity, List<OfferStatusData> offerList) {
this.activity = activity;
this.offerList = (ArrayList)offerList;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// bgColors = activity.getApplicationContext().getResources().getStringArray(R.array.movie_serial_bg);
}
@Override
public int getCount() {
return offerList.size();
}
@Override
public Object getItem(int location) {
return offerList.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder ;
if (convertView == null) {
convertView = inflater.inflate(R.layout.row_offer_status, null);
holder = new ViewHolder();
// holder.tvCustomerName = (TextView) convertView.findViewById(R.id.tv_row_customer_name);
holder.tvOfferName = (TextView) convertView.findViewById(R.id.row_offer_name);
// holder.tvEmail = (TextView) convertView.findViewById(R.id.row_email);
holder.tvPhoneNumber = (TextView) convertView.findViewById(R.id.row_phone_number);
holder.tvAddress = (TextView) convertView.findViewById(R.id.row_address);
holder.tvTmcBrand = (TextView) convertView.findViewById(R.id.row_tmc_brand);
holder.tvStartEndTime = (TextView) convertView.findViewById(R.id.row_offer_time);
holder.tvNoOfPerson = (TextView) convertView.findViewById(R.id.tv_row_total_person);
holder.tvNoOfAcceptors = (TextView) convertView.findViewById(R.id.tv_row_total_acceptors);
holder.tvMonth = (TextView) convertView.findViewById(R.id.tv_row_month);
holder.tvDay = (TextView) convertView.findViewById(R.id.tv_row_day);
// holder.tvCustomerName = (TextView) convertView.findViewById(R.id.tv_row_customer_name);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
if(offerList.size()>0){
offerStatusData = (OfferStatusData)offerList.get(position);
// holder.tvCustomerName.setText(offerStatusData.getName());
holder.tvOfferName.setText(offerStatusData.getOffer_name());
// holder.tvEmail.setText(offerStatusData.getEmail());
holder.tvPhoneNumber.setText(offerStatusData.getPhone_number());
holder.tvAddress.setText(offerStatusData.getAddress());
holder.tvTmcBrand.setText(offerStatusData.getTmc_brand());
holder.tvStartEndTime.setText(offerStatusData.getStart_time()+"-"+offerStatusData.getEnd_time());
holder.tvNoOfPerson.setText(offerStatusData.getNo_of_person());
holder.tvNoOfPerson.setTextColor(Color.parseColor("#F66D0D"));
holder.tvNoOfAcceptors.setText(offerStatusData.getCurrent_acceptors()+"/"+offerStatusData.getNo_of_person());
holder.tvNoOfAcceptors.setTextColor(Color.parseColor("#2B5BD2"));
// holder.tvMonth.setText("july");
// holder.tvDay.setText("29");
String dateFromService = offerStatusData.getDate();
String[] monthFromService = dateFromService.split("-");
Log.d("date split", dateFromService.toString());
holder.tvDay.setText(monthFromService[2].toString());
holder.tvDay.setTextColor(Color.parseColor("#57902B"));
holder.tvMonth.setText(getMonth(Integer.parseInt(monthFromService[1])));
holder.tvMonth.setTextColor(Color.parseColor("#57902B"));
}
return convertView;
// String color = bgColors[position % bgColors.length];
// serial.setBackgroundColor(Color.parseColor(color));
}
void delete (int post){
offerList.remove(post);
}
class ViewHolder{
TextView tvOfferName,tvPhoneNumber,tvAddress,
tvTmcBrand,tvStartEndTime,tvNoOfPerson,tvNoOfAcceptors,tvMonth,tvDay;
}
public String getMonth(int month) {
return new DateFormatSymbols().getShortMonths()[month-1];
// return new DateFormatSymbols().getMonths()[month-1];
}
}
所以我真的不知道这背后的主要原因是什么,没有任何线索留给我。请告诉我可能是什么问题。
答案 0 :(得分:0)
试试这个,
listView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow View pager to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow View pager to intercept touch events.
// v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
// Handle Listview touch events.
v.onTouchEvent(event);
return true;
}
});