ListView with empty rows

0

Hi, I have a doubt, I have a listView which is filled with a JsonArray list, my problems is that being dynamic that list is filled with a database which can come with 2 elements or can come with 100 elements I keep them in a container which by default shows me 10 items, giving a fixed size to that list approx. 300dp the problem is that when the list is less than 10 bone it only brings two elements but it leaves an empty blank space I need a way in which I can fill the rest of the list for example the other 8 spaces that are left and < a href="https://i.stack.imgur.com/zMyJE.png"> enter the description of the image here that puts them as empty rows to simulate a kind of attached notebook an image in which in ios if you can I would like to replicate the same and attach the code of my adapter. Thank you. is a row that contains four elements

code: public class SimpleAdapterHistoric extends BaseAdapter {     private static LayoutInflater inflater = null;     Context context;     private JSONArray jsonArray;

public SimpleAdapterHistoric(Context context, JSONArray jsonArray) {
    this.context = context;
    this.jsonArray = jsonArray;
    inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    final View rowView = inflater.inflate(R.layout.simple_adapter_historic, null);

    TextView one= (TextView) rowView.findViewById(R.id.historic_element_first);
    TextView two = (TextView) rowView.findViewById(R.id.historic_element_second);
    TextView three = (TextView) rowView.findViewById(R.id.historic_element_third);
    TextView four = (TextView) rowView.findViewById(R.id.historic_element_fourth);
    try {
        one.setText((String) ((JSONObject) jsonArray.get(i)).get("firstValor"));
        two.setText((String) ((JSONObject) jsonArray.get(i)).get("secondValor"));
        three.setText((String) ((JSONObject) jsonArray.get(i)).get("threeValor"));
        four.setText((String) ((JSONObject) jsonArray.get(i)).get("lowValor"));

    } catch (Exception e) {
        one.setText("");
        two.setText("");
        three.setText("");
        four.setText("");
    }
    return rowView;
}

@Override
public int getCount() {

    return jsonArray.length();
}

@Override
public Object getItem(int i) {
    try {
        return jsonArray.get(i);
    } catch (Exception e) {
        return null;
    }
}

@Override
public long getItemId(int i) {

    return i;
}

}

    
asked by Alejandro 09.03.2018 в 20:56
source

0 answers