滑动到删除从列表视图的顶部项不起作用,但从列表视图的最后一项不起作用 [英] Swipe to Delete Not working from the Top item of the listview but from the last item of list view
问题描述
我正在使用此作为要删除的内容.但我在仅实现列表的删除菜单项时遇到问题.
I am Using the this as swipe to delete. but I am having problem in implementing only the delete menu item of the list.
我正在做的只是创建一个删除项目.我真的不想使用演示中显示的其他任何项目,例如打开".
What I am doing is creating just one single delete Item. I really do not want to use any other item such like Open as shown in demo.
这是我的设计
<?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>
这是我如何在片段"中创建菜单
and here is How I Am creating my menu in my Fragment
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);
}
};
这是我设置创作者的方式
here is how I am setting creator
// set creator
mListView.setMenuCreator(creator);
我的问题,如前所述,我有一些关于删除的问题
My Problem I have couple of problems regarding to the delete, as mentioned
- 当列表中的数据过多时,假设行数为10,需要向下滚动,即使从列表视图的第一行开始,删除选项也像超级按钮一样工作.
- 当列表中的项目较少时,或者如果我继续从底部删除项目,我的意思是最后一行,当不需要向下滚动的项目较少时,无法顺利删除,则需要花费很多时间刷新列表,或从右至左再次打开和关闭菜单,在删除菜单上进行许多操作,然后经过多次尝试后删除一些内容.
- 我不知道背后的问题是什么,但是当我创建了两个菜单(如演示中所示的打开"和删除")时,我同时将打开"和删除"作为删除"按钮,因此在案例0和案例1中,我写了delete的代码,然后我注意到每次按open时,删除都是有效的,但是当我按delete时,再次删除它有时会删除该项目,或者需要花费很多时间才能进行多次尝试.
可能是什么问题?有什么猜想吗?有什么解决方法吗?
What could be problem ? Any guess ? Is there any work around ?
是的,可以肯定的是,当我轻触删除菜单时,它会给我一个日志,在下面向下看,它在日志中向我显示此内容,当我轻触以进行删除和删除时,实际上是行不通的,但是当它执行时开始工作时,此消息在日志中永远不会显示.
And Yeah On thing for sure , When I touch the delete menu it gives me a Log , look down below, It show me this in log , when I Touch to delete and delete is in fact not working , but when it does start working this message in log never shows up.
D/ViewRootImpl:ViewPostImeInputStage ACTION_DOWN
D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
编辑一个
这是我的适配器的完整代码:
Here is my whole code of adapter :
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];
}
}
所以我真的不知道背后的主要原因是什么,我没有头绪.请告诉我可能是什么问题.
So I really do not know what is the main reason behind this , No clue left for me. Please tell me what could be the problem.
推荐答案
尝试一下,
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;
}
});
这篇关于滑动到删除从列表视图的顶部项不起作用,但从列表视图的最后一项不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!