Reputation: 81
how to remove a space even I am succeed in hiding a row, but it shows a white space in there. It will hide a row when Status will be equal to 'Awarded' as given below. help me thanks in advance.
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 Shot of rows
Upvotes: 3
Views: 275
Reputation: 3359
You need to create adapter that will return the total number of not null items with getCount() and then keep a getting the positions of your data.
Ex. You are having a list as position 1 - A , 2 - B, 3 - null, 4 - D, 5 - null
When getCount is called it returns 3.
at that time getView is called on position 1 you return the item at list[1]. getView on position 3 returns list[4] (as 4th position is non-null), and so on.
Upvotes: 1