如果我删除填充,滑动手势无法正常工作

时间:2016-10-12 08:54:54

标签: android fragment padding swipe

嗨,大家好我是android的新手,所以如果我问一个愚蠢的问题,请耐心等待。 我试图在listfragment中实现左右滑动手势,并在滑动时使用不同的布局重新加载片段。 但是滑动动作在列表视图的角落处起作用(即,如果填充了根布局)。 如果我尝试通过触摸列表视图滑动它不起作用。 请帮忙。 Screenshot for the issue is here 这是我的活动方法::

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_actionable);

    initialize();
    replaceFragment(factordetailsFrag);
    //addDataToInvoicetable();
    frag_container.setOnTouchListener(new OnSwipeTouchListener(this) {
        @Override
        public void onSwipeLeft() {
            //replaceFragment(invoiceDetailsFrag);
            replaceFragment(list_view_demo_frag);
        }

        @Override
        public void onSwipeRight() {
            replaceFragment(factordetailsFrag);
        }
    });


    /*list_view_demo_frag.getListView().setOnTouchListener(new OnSwipeTouchListener(this){
        @Override
        public void onSwipeLeft() {
            //replaceFragment(invoiceDetailsFrag);
            replaceFragment(list_view_demo_frag);
        }

        @Override
        public void onSwipeRight() {
            replaceFragment(factordetailsFrag);
        }
    });*/

    //ListView view = (ListView)findViewById(and);

}

ListFragmentDemoClass ::

public class ListFragmentDemo extends ListFragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.custom, container, false);

    return view;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    //ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.Planets, android.R.layout.simple_list_item_1);
    ListViewAdapter adapter = new ListViewAdapter(getActivity(), getData());
    setListAdapter(adapter);
}

private ArrayList<invoiceDetailsModel> getData() {
    ArrayList<invoiceDetailsModel> returnlist = new ArrayList<>();

    invoiceDetailsModel obj1 = new invoiceDetailsModel();
    obj1.setAmount("1000");
    obj1.setInvNum("AB--nsdfj");
    obj1.setApprovedAmount("200");
    returnlist.add(obj1);

    invoiceDetailsModel obj2 = new invoiceDetailsModel();
    obj2.setAmount("1030");
    obj2.setInvNum("GF--nsdfj");
    obj2.setApprovedAmount("20");
    returnlist.add(obj2);

    invoiceDetailsModel obj3 = new invoiceDetailsModel();
    obj3.setAmount("10000");
    obj3.setInvNum("AT");
    obj3.setApprovedAmount("200");
    returnlist.add(obj3);

    for (int i=0; i<400;i++){
        invoiceDetailsModel obj = new invoiceDetailsModel();
        obj.setAmount("10000");
        obj.setInvNum("AT--"+Integer.toString(i));
        obj.setApprovedAmount("200");
        returnlist.add(obj3);

    }
    return returnlist;
}

@Override
public void setEmptyText(CharSequence text) {
    super.setEmptyText(text);
}

}

我的适配器类::

public class ListViewAdapter extends BaseAdapter {

private ArrayList<invoiceDetailsModel> listData;
private LayoutInflater layoutInflater;
Activity activity;
TextView txtFirst;
TextView txtSecond;
TextView txtThird;
TextView txtFourth;
public ListViewAdapter(Activity activity, ArrayList<invoiceDetailsModel> list){
    super();
    this.activity=activity;
    this.listData=list;

    /*for (invoiceDetailsModel temp: listData){
        Log.i("sammy",temp.getAmount());
        Log.i("sammy",temp.getApprovedAmount());
        Log.i("sammy",temp.getInvNum());
    }*/
}


@Override
public int getCount() {
    Log.i("sammy","The list is called with size::"+listData.size());
    if (listData==null){return 0;}
    return listData.size();
}

@Override
public Object getItem(int position) {
    if (listData==null){ return null;}
    return listData.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;

    if(convertView == null){
        //LayoutInflater.from(activity).inflate()
        holder = new ViewHolder();
        this.layoutInflater = activity.getLayoutInflater();
        convertView=layoutInflater.inflate(R.layout.colmn_row, null);
        convertView.setTag(holder);
        holder.invNumView = (TextView) convertView.findViewById(R.id.invNum);
        holder.amountView = (TextView) convertView.findViewById(R.id.amount);
        holder.approvedAmountView = (TextView) convertView.findViewById(R.id.approvedAmnt);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
   // holder = new ViewHolder();

    if (listData!=null){
        holder.invNumView.setText(listData.get(position).getInvNum());
        holder.amountView.setText(listData.get(position).getAmount());
        holder.approvedAmountView.setText(listData.get(position).getApprovedAmount());
    }

    return convertView;
}

/*@Override
public boolean isEnabled(int position) {
    return false;
}*/

class ViewHolder {
    TextView invNumView;
    TextView amountView;
    TextView approvedAmountView;
}

}

0 个答案:

没有答案