Hide a list of lines without occupying spaces in it
how to remove the space, even I manage to hide the line, but there is a space displayed. It will hide the line when the status is "Awarded" as indicated below. help me ahead of time.
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;
}
}
Screen Snapshot
+3
user3440768
source
to share
1 answer
You need to create an adapter that will return the total number of non-null elements using getCount () and then store the positions of your data.
Example You have a list as position 1 - A, 2 - B, 3 - null, 4 - D, 5 - null
When getCount is called, it returns 3.
while getView is called at position 1, you are returning an item in list [1]. getView at position 3 returns list [4] (since 4th position is not zero), etc.
+1
Krupa patel
source
to share