gpt4 book ai didi

android - 隐藏 ListView 行而没有间距

转载 作者:太空狗 更新时间:2023-10-29 14:09:04 27 4
gpt4 key购买 nike

如何删除一个空格,即使我成功地隐藏了一行,但它在那里显示了一个空白。当 Status 等于“Awarded”时,它将隐藏一行,如下所示。帮我提前谢谢。

import android.app.Activity;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListViewAdapter extends BaseAdapter {

Activity context;
String ref[];
String policy[];
String natureofloss[];
String make[];
String registration[];
String modelname[];
String year[];
String amount[];
String status[];
String quot_id[];

public ListViewAdapter(Activity context, String[] ref, String[] policy,
String[] natureofloss, String[] make, String[] registration,
String[] modelname, String[] year, String[] amount,
String[] status, String[] qout_id) {
super();
this.context = context;
this.ref = ref;
this.policy = policy;
this.natureofloss = natureofloss;
this.make = make;
this.registration = registration;
this.modelname = modelname;
this.year = year;
this.amount = amount;
this.status = status;
this.quot_id = qout_id;
}

public int getCount() {
// TODO Auto-generated method stub
return ref.length;
}

public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}

public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}

private class ViewHolder {
TextView ref;
TextView policy;
TextView natureofloss;
TextView make;
TextView registration;
TextView modelname;
TextView year;
TextView amount;
TextView status;
TextView quot_id;

}

public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
LayoutInflater inflater = context.getLayoutInflater();

if (convertView == null) {
convertView = inflater.inflate(R.layout.rowitem, null);
holder = new ViewHolder();
holder.ref = (TextView) convertView
.findViewById(R.id.tv_refpolicyno);
holder.policy = (TextView) convertView
.findViewById(R.id.tv_policyno);
holder.natureofloss = (TextView) convertView
.findViewById(R.id.tv_natureofloss);
holder.make = (TextView) convertView.findViewById(R.id.tv_make);
holder.registration = (TextView) convertView
.findViewById(R.id.tv_registration);
holder.modelname = (TextView) convertView
.findViewById(R.id.tv_modelname);
holder.year = (TextView) convertView.findViewById(R.id.tv_year);
holder.amount = (TextView) convertView.findViewById(R.id.tv_amount);
holder.status = (TextView) convertView.findViewById(R.id.tv_status);
holder.quot_id = (TextView) convertView
.findViewById(R.id.tv_quotid_clientqoutlist);

convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

if (!status[position].equals("Awarded")) {
holder.ref.setText(ref[position]);
holder.policy.setText("/" + policy[position]);
holder.natureofloss.setText(natureofloss[position]);
holder.make.setText(make[position]);
holder.registration.setText(registration[position]);
holder.modelname.setText(modelname[position]);
holder.year.setText(year[position]);
holder.amount.setText(amount[position]);
holder.status.setText(status[position]);
holder.quot_id.setText(quot_id[position]);
} else {
convertView.setVisibility(View.GONE);

}

return convertView;
}

}

行的屏幕截图

enter image description here

最佳答案

您需要创建适配器,它将使用 getCount() 返回非空项目的总数,然后继续获取数据的位置。

Ex. 您的列表位置为 1 - A 、2 - B、3 - null、4 - D、5 - null

调用 getCount 时返回 3。

此时 getView 在位置 1 上调用,您返回列表 [1] 中的项目。位置 3 上的 getView 返回列表[4](因为第 4 个位置不为空),依此类推。

关于android - 隐藏 ListView 行而没有间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30498813/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com