如何在android中为可扩展listview中的子级设置限制

如何在android中为可扩展listview中的子级设置限制,android,listview,Android,Listview,我正在创建一个包含listview的android应用程序 在listview中,我有一个可扩展的高度listview。对于父listview,我将限制设置为仅显示两个列表项。但是在可扩展列表视图中,我没有设置任何限制。 我想知道如何为listview中的子视图(即可扩展listview)设置限制。下面是我的listview one适配器代码: public class Daybook_adapter extends BaseAdapter { Context context;

我正在创建一个包含listview的android应用程序
在listview中,我有一个可扩展的高度listview。对于父listview,我将限制设置为仅显示两个列表项。但是在可扩展列表视图中,我没有设置任何限制。
我想知道如何为listview中的子视图(即可扩展listview)设置限制。下面是我的listview one适配器代码:

  public class Daybook_adapter extends BaseAdapter {
    Context context;
    Activity activity;


    //DaybookSwipeMenuListView daybookdetailviewlist;
    public Daybook_adapter(Activity activity, ArrayList<Daybook> list) {

        //this.context = context;
        this.activity = activity;
        entriesdaybook = list;

    }


    @Override
    public int getCount() {

        return entriesdaybook.size();
    }

    @Override
    public Object getItem(int position) {

        return entriesdaybook.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {


        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.model_daybook, null);

        }


        final Daybook m = entriesdaybook.get(position);
        final TextView tv_date = (TextView) convertView.findViewById(R.id.tv_daybook_date);
        final TextView tv_cashin = (TextView) convertView.findViewById(R.id.tv_daybook_cashin);
        final TextView tv_cashout = (TextView) convertView.findViewById(R.id.tv_daybook_cashout);
        final TextView tv_totalamt = (TextView) convertView.findViewById(R.id.daybook_total_amt);
        final ImageView img_pdf = (ImageView) convertView.findViewById(R.id.img_printpdf);
        //final String s = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        String s = m.getDate();
        emptyyz = (LinearLayout) convertView.findViewById(R.id.empty);
        // daybookdetailviewlist = (DaybookSwipeMenuListView) convertView.findViewById(R.id.detaillist_daybook);
        daybookdetailviewlist = (ExpandableHeightListView) convertView.findViewById(R.id.detaillist_daybook);

        String[] spiliter = s.split("-");
        String year = spiliter[0];
        String month = spiliter[1];
        String date = spiliter[2];
        if (month.startsWith("01")) {
            tv_date.setText(date + "Jan" + year);
        } else if (month.startsWith("02")) {
            tv_date.setText(date + "Feb" + year);
        } else if (month.startsWith("03")) {
            tv_date.setText(date + "Mar" + year);
        } else if (month.startsWith("04")) {
            tv_date.setText(date + "Apr" + year);
        } else if (month.startsWith("05")) {
            tv_date.setText(date + "May" + year);
        } else if (month.startsWith("06")) {
            tv_date.setText(date + "Jun" + year);
        } else if (month.startsWith("07")) {
            tv_date.setText(date + "Jul" + year);
        } else if (month.startsWith("08")) {
            tv_date.setText(date + "Aug" + year);
        } else if (month.startsWith("09")) {
            tv_date.setText(date + "Sep" + year);
        } else if (month.startsWith("10")) {
            tv_date.setText(date + "Oct" + year);
        } else if (month.startsWith("11")) {
            tv_date.setText(date + "Nov" + year);
        } else if (month.startsWith("12")) {
            tv_date.setText(date + "Dec" + year);
        }


   /* if (m.getUsertype().startsWith("singleworker")) {
        tv_cashin.setText("\u20B9" + "0");
    } else if (m.getUsertype().startsWith("groupworker")) {
        tv_cashin.setText("\u20B9" + "0");
    }*/

        tv_cashin.setText("\u20B9" + m.getCashin());
        tv_cashout.setText("\u20B9" + m.getCashout());
        double one = Double.parseDouble(m.getCashin());
        double two = Double.parseDouble(m.getCashout());
        double three = one + two;
        tv_totalamt.setText("\u20B9" + String.valueOf(three));
        // new DaybooklistAsynccTask().execute(s);
        databaseHandler = new DatabaseHandler(activity);
        daybooklists = databaseHandler.getAllDaywisedaybookdetails(s);
        adapter = new Daybooklist_adapter(activity, daybooklists);
        if (adapter != null) {
            if (adapter.getCount() > 0) {
                emptyy.setVisibility(View.GONE);
                daybookdetailviewlist.setAdapter(adapter);

            }
        } else {
            daybookdetailviewlist.setEmptyView(emptyyz);
        }
        daybookdetailviewlist.setExpanded(true);


        img_pdf.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                final android.support.v7.app.AlertDialog.Builder alert = new android.support.v7.app.AlertDialog.Builder(
                        activity);
                alert.setTitle(activity.getResources().getString(R.string.app_name));
                alert.setMessage("Click yes to Print Report for" + m.getDate());
                alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent pdfreport = new Intent(activity, Activity_Daybookpdf.class);
                        pdfreport.putExtra("date", m.getDate());
                        activity.startActivity(pdfreport);

                    }
                });
                alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();


                    }
                });

                alert.show();
                return false;
            }
        });


        return convertView;

    }

    private int dp2px(int dp) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
                activity.getResources().getDisplayMetrics());
    }

    public void setTransactionList(ArrayList<Daybook> newList) {
        entriesdaybook = newList;
        notifyDataSetChanged();
    }



}
公共类Daybook\u适配器扩展了BaseAdapter{
语境;
活动;
//DaybookSwipeMenuListView daybookdetailviewlist;
公共Daybook_适配器(活动,ArrayList列表){
//this.context=上下文;
这个。活动=活动;
entriesdaybook=列表;
}
@凌驾
public int getCount(){
return entriesdaybook.size();
}
@凌驾
公共对象getItem(int位置){
返回entriesdaybook.get(位置);
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组arg2){
if(convertView==null){
LayoutFlater充气机=(LayoutFlater)活动
.getSystemService(上下文布局\充气机\服务);
convertView=充气机。充气(R.layout.model_daybook,空);
}
最终日记帐m=entriesdaybook.get(位置);
最终文本视图tv_日期=(文本视图)convertView.findViewById(R.id.tv_daybook_日期);
final TextView tv_cashin=(TextView)convertView.findviewbyd(R.id.tv_daybook_cashin);
最终文本视图tv_兑现=(文本视图)convertView.findViewById(R.id.tv_daybook_兑现);
最终文本视图tv_totalamt=(文本视图)convertView.findViewById(R.id.daybook_total_amt);
最终ImageView img_pdf=(ImageView)convertView.findViewById(R.id.img_printpdf);
//最终字符串s=新的SimpleDataFormat(“yyyy-MM-dd”).format(新日期());
字符串s=m.getDate();
emptyyz=(LinearLayout)convertView.findViewById(R.id.empty);
//daybookdetailviewlist=(DaybookSwipeMenuListView)convertView.findViewById(R.id.detaillist\u daybook);
daybookdetailviewlist=(ExpandableHeightListView)convertView.findViewById(R.id.detaillist\u daybook);
字符串[]Spill=s.split(“-”);
串年=每升[0];
字符串月份=每升[1];
字符串日期=每升[2];
如果(从(“01”)开始的月份){
tv_date.setText(日期+一月+年份);
}如果(从(“02”)开始的月份){
tv_date.setText(日期+2月+年份);
}如果(从(“03”)开始的月份){
tv_date.setText(日期+三月+年份);
}否则,如果(从(“04”)开始的月份){
tv_date.setText(日期+四月+年份);
}否则,如果(从(“05”)开始的月份){
tv_date.setText(日期+五月+年份);
}否则,如果(从(“06”)开始的月份){
tv_date.setText(日期+六月+年份);
}否则,如果(从(“07”)开始的月份){
tv_date.setText(日期+七月+年份);
}否则,如果(从(“08”)开始的月份){
tv_date.setText(日期+八月+年份);
}如果(从(“09”)开始的月份){
tv_date.setText(日期+九月+年份);
}否则,如果(从(“10”)开始的月份){
tv_date.setText(日期+10月+年份);
}否则,如果(从(“11”)开始的月份){
tv_date.setText(日期+11月+年份);
}否则,如果(从(“12”)开始的月份){
tv_date.setText(日期+十二月+年份);
}
/*if(m.getUsertype().startsWith(“singleworker”)){
tv_cashin.setText(“\u20B9”+“0”);
}else if(m.getUsertype().startsWith(“groupworker”)){
tv_cashin.setText(“\u20B9”+“0”);
}*/
tv_cashin.setText(“\u20B9”+m.getCashin());
tv_cashout.setText(“\u20B9”+m.getCashout());
double-one=double.parseDouble(m.getCashin());
double-two=double.parseDouble(m.getCashout());
双三=一+二;
tv_totalamt.setText(“\u20B9”+字符串.valueOf(三个));
//新建DaybooklistAsynccTask()。执行;
databaseHandler=新的databaseHandler(活动);
DayBookList=databaseHandler.getAllDaywisedaybookdetails;
适配器=新的Daybooklist_适配器(活动、Daybooklist);
if(适配器!=null){
if(adapter.getCount()>0){
emptyy.setVisibility(View.GONE);
daybookdetailviewlist.setAdapter(适配器);
}
}否则{
daybookdetailviewlist.setEmptyView(emptyyz);
}
daybookdetailviewlist.setExpanded(true);
img_pdf.setOnTouchListener(新视图.OnTouchListener()){
@凌驾
公共布尔onTouch(视图、运动事件、运动事件){
最终android.support.v7.app.AlertDialog.Builder alert=新的android.support.v7.app.AlertDialog.Builder(
活动);
alert.setTitle(activity.getResources().getString(R.string.app_name));
alert.setMessage(“单击“是”打印“+m.getDate()”的报告);
alert.setPositiveButton(“是”,新的DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
Intent pdfreport=新的Intent(activity,activity\u Daybookpdf.class);
pdfreport.putExtra(“日期”,m.getDate());
活动。开始活动(pdfreport);
}
});
alert.setNegativeButton(“否”,新的DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
dialog.dismise();
}
});
public class Daybooklist_adapter extends BaseAdapter {
Context context;
private Activity activity;
private LayoutInflater inflater;
private ArrayList<Daybooklist> daybooklists;
DatabaseHandler databaseHandler;

public Daybooklist_adapter(Activity activity, ArrayList<Daybooklist> daybooklists) {
    this.activity = activity;
    this.daybooklists = daybooklists;
}

@Override
public int getCount() {
    return daybooklists.size();
}

@Override
public Object getItem(int i) {
    return daybooklists.get(i);
}

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

@Override
public View getView(int position, View convertview, ViewGroup parent) {
    if (inflater == null)
        inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertview == null)
        convertview = inflater.inflate(R.layout.model_daybook_listentry, null);
    final TextView day_name = (TextView) convertview.findViewById(R.id.tv_daybook_name);
    final TextView day_description = (TextView) convertview.findViewById(R.id.tv_daybook_description);
    final TextView day_type = (TextView) convertview.findViewById(R.id.tv_daybook_type);
    final TextView day_amount = (TextView) convertview.findViewById(R.id.tv_daybook_amount);
    final TextView day_usertype = (TextView) convertview.findViewById(R.id.tv_usertype);
    final TextView day_time = (TextView) convertview.findViewById(R.id.tv_daybook_time);
    final ImageView day_check = (ImageView) convertview.findViewById(R.id.img_doneall);
    final TextView daybook_location = (TextView) convertview.findViewById(R.id.tv_daybook_location);
    databaseHandler = new DatabaseHandler(activity);
    // getting movie data for the row

    final Daybooklist m = daybooklists.get(position);
    if (m.getUsertype() != null && !m.getUsertype().isEmpty()) {
        if (m.getUsertype().startsWith("farmer") | m.getUsertype().startsWith("singleworker") | m.getUsertype().startsWith("groupworker") | m.getUsertype().startsWith("payvehicle")) {
            if (m.getUsertype().startsWith("farmer")) {
                day_name.setText(m.getName());
                day_description.setText(m.getDescription());
                String locat = String.valueOf(databaseHandler.getfarmerlocation(m.getMobileno()));
                locat = locat.replaceAll("\\[", "").replaceAll("\\]", "");
                Log.e("farmerlocation", locat);
                daybook_location.setText(locat);
                day_type.setText(m.getType());
                if (m.getName() != null && m.getName().startsWith("no")) {
                    day_name.setText(" ");
                } else if (m.getDescription() != null && m.getDescription().startsWith("no")) {
                    day_description.setText(" ");
                }

                day_amount.setText("\u20B9" + m.getExtraamt());
                if (m.getAmountout().startsWith("0.0") | m.getAmountout().startsWith("0")) {
                    day_amount.setTextColor(activity.getResources().getColor(R.color.green));
                    Log.e("Amountout", m.getAmountout());
                    day_check.setVisibility(View.INVISIBLE);
                } else {
                    day_amount.setTextColor(activity.getResources().getColor(R.color.album_title));
                    Log.e("Amountout", m.getAmountout());
                    day_check.setVisibility(View.VISIBLE);
                }

                day_time.setText(m.getCtime());
            } else {
                day_name.setText(m.getName());
                day_description.setText(m.getDescription());
                daybook_location.setText(m.getType());
                day_type.setText(m.getType());
                if (m.getName() != null && m.getName().startsWith("no")) {
                    day_name.setText(" ");
                } else if (m.getDescription() != null && m.getDescription().startsWith("no")) {
                    day_description.setText(" ");
                }

                day_amount.setText("\u20B9" + m.getExtraamt());
                if (m.getAmountout().startsWith("0.0") | m.getAmountout().startsWith("0")) {
                    day_amount.setTextColor(activity.getResources().getColor(R.color.green));
                    Log.e("Amountout", m.getAmountout());
                    day_check.setVisibility(View.INVISIBLE);
                } else {
                    day_amount.setTextColor(activity.getResources().getColor(R.color.album_title));
                    Log.e("Amountout", m.getAmountout());
                    day_check.setVisibility(View.VISIBLE);
                }

                day_time.setText(m.getCtime());
            }


        } else if (m.getUsertype().startsWith("advancefarmer") | m.getUsertype().startsWith("workeradvance") | m.getUsertype().startsWith("kgroupadvance") | m.getUsertype().startsWith("otherexpense") | m.getUsertype().startsWith("vehicle")) {
            if (m.getUsertype().startsWith("advancefarmer")) {
                day_name.setText(m.getName());
                day_description.setText(m.getDescription());
                day_type.setText(m.getType());
                String locat = String.valueOf(databaseHandler.getfarmerlocation(m.getMobileno()));
                locat = locat.replaceAll("\\[", "").replaceAll("\\]", "");
                Log.e("farmerlocation", locat);
                daybook_location.setText(locat);
                if (m.getName() != null && m.getName().startsWith("no")) {
                    day_name.setText(" ");
                } else if (m.getDescription() != null && m.getDescription().startsWith("no")) {
                    day_description.setText(" ");
                }
                Log.e("amountout", m.getAmountout());
                day_amount.setText("\u20B9" + m.getAmountout());
                day_time.setText(m.getCtime());
            } else {
                day_name.setText(m.getName());
                day_description.setText(m.getType());
                day_type.setText(m.getType());
                daybook_location.setText(m.getDescription());
                if (m.getName() != null && m.getName().startsWith("no")) {
                    day_name.setText(" ");
                } else if (m.getDescription() != null && m.getDescription().startsWith("no")) {
                    day_description.setText(" ");
                }
                Log.e("amountout", m.getAmountout());
                day_amount.setText("\u20B9" + m.getAmountout());
                day_time.setText(m.getCtime());
            }


        } else if (m.getUsertype().startsWith("buyer")) {
            day_name.setText(m.getName());
            day_description.setText(m.getDescription());
            day_amount.setText("\u20B9" + m.getAmountin());
            day_type.setText(" ");
            day_time.setText(m.getCtime());
            daybook_location.setText(m.getType());
        }
        if (m.getUsertype().startsWith("farmer")) {
            day_usertype.setText("F");
            day_usertype.setBackgroundResource(R.drawable.textview_farmer);
        } else if (m.getUsertype().startsWith("advancefarmer")) {
            day_usertype.setText("FA");
            day_usertype.setBackgroundResource(R.drawable.textview_farmer);
        } else if (m.getUsertype().startsWith("singleworker")) {
            day_usertype.setText("W");
            day_usertype.setBackgroundResource(R.drawable.textview_worker);
        } else if (m.getUsertype().startsWith("workeradvance")) {
            day_usertype.setText("WA");
            day_usertype.setBackgroundResource(R.drawable.textview_worker);
        } else if (m.getUsertype().startsWith("groupworker")) {
            day_usertype.setText("G");
            day_usertype.setBackgroundResource(R.drawable.textview_worker);
        } else if (m.getUsertype().startsWith("kgroupadvance")) {
            day_usertype.setText("GA");
            day_usertype.setBackgroundResource(R.drawable.textview_worker);
        } else if (m.getUsertype().startsWith("otherexpense")) {
            day_usertype.setText("E");
            day_usertype.setBackgroundResource(R.drawable.textview_otherexpense);
        } else if (m.getUsertype().startsWith("vehicle")) {
            day_usertype.setText("V");
            day_usertype.setBackgroundResource(R.drawable.textview_vehicle);

        } else if (m.getUsertype().startsWith("gsalary")) {
            day_usertype.setText("GS");
            day_usertype.setBackgroundResource(R.drawable.textview_worker);
        } else if (m.getUsertype().startsWith("isalary")) {
            day_usertype.setText("WS");
            day_usertype.setBackgroundResource(R.drawable.textview_worker);
        } else if (m.getUsertype().startsWith("payvehicle")) {
            day_usertype.setText("VP");
            day_usertype.setBackgroundResource(R.drawable.textview_vehicle);
        } else if (m.getUsertype().startsWith("buyer")) {
            day_usertype.setText("B");
            day_usertype.setBackgroundResource(R.drawable.textview_buyer);
        }
    }


    convertview.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            if (m.getUsertype().startsWith("farmer") | m.getUsertype().startsWith("advancefarmer")) {
                String name = m.getName();
                String mobno = m.getMobileno();
                Intent a = new Intent(activity, FarmerLedgerView_Activity.class);
                a.putExtra("farmername", name);
                a.putExtra("farmermobno", mobno);
                activity.startActivity(a);
            } else if (m.getUsertype().startsWith("singleworker") | m.getUsertype().startsWith("workeradvance")) {
                String name = m.getName();
                String mobno = m.getMobileno();
                Intent c = new Intent(activity, WorkerLedger_Activity.class);
                c.putExtra("workername", name);
                c.putExtra("workermobno", mobno);
                activity.startActivity(c);
            } else if (m.getUsertype().startsWith("groupworker") | m.getUsertype().startsWith("kgroupadvance")) {
                String name = m.getName();
                String mobno = m.getMobileno();
                Intent g = new Intent(activity, GroupWorkerLedger_Activity.class);
                g.putExtra("groupname", name);
                g.putExtra("workermobno", mobno);
                activity.startActivity(g);
            } else if (m.getUsertype().startsWith("isalary")) {
                String name = m.getName();
                String mobno = m.getMobileno();
                Intent d = new Intent(activity, Worker_paymenthistory_Activity.class);
                d.putExtra("workername", name);
                d.putExtra("workermobno", mobno);
                activity.startActivity(d);
            } else if (m.getUsertype().startsWith("bsalary")) {
                Intent aa = new Intent(activity, WorkerListActivity.class);
                activity.startActivity(aa);
            } else if (m.getUsertype().startsWith("vehicle") | m.getUsertype().startsWith("payvehicle")) {
                //// TODO: 19-Dec-16  enable this
                Intent s = new Intent(activity, VehicleList_activity.class);
                activity.startActivity(s);
            } else if (m.getUsertype().startsWith("otherexpense")) {
                Intent b = new Intent(activity, OtherExpenseList.class);
                activity.startActivity(b);
            } else if (m.getUsertype().startsWith("buyer")) {
                String name = m.getName();
                String mobno = m.getMobileno();
                Intent buyer = new Intent(activity, BuyerLedgerViewActivity.class);
                buyer.putExtra("buyername", name);
                buyer.putExtra("buyermobno", mobno);
                activity.startActivity(buyer);

            }
        }
    });
    return convertview;
}

private int dp2px(int dp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics());
}
 @Override
    public int getCount() {
    if(daybooklists.size()>2)
        return 2;
    else 
    return daybooklists.size();
    }