1

I have a layout for a fragment which contains a textview inside a tableview, and I want to set its text whenever a new row is added.

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View v = inflater.inflate(R.layout.home_fragment,container,false);

            doctorNameTextView = (TextView) v.findViewById(R.id.doctorNameTextView);

            tableLayout = (TableLayout) v.findViewById(R.id.tableLayout1);
            tableLayout.removeAllViews();
            showDoctorList();

            return v;
        }



public void showDoctorList() {
    String result = "Match Found";

    context = this.getActivity();

    MyDBHandler dbHandler = new MyDBHandler(context, null, null, 1);

    ArrayList<ArrayList<String>> docArray = new ArrayList<ArrayList<String>>();

    DoctorDataModel doctor = null;
    try {
        doctor = dbHandler.showDoctors();
    } catch (SQLException e) {
        e.printStackTrace();
    }

    if (doctor != null) {

        docArray = doctor.getDocArray();

        for(int i = 0; i < docArray.size(); i++) {

            TableRow row = new TableRow(getActivity());
            row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

            for(int j = 1; j < docArray.get(i).size(); j++) {

                if(j == 1) {
                    result = "Dr. " + docArray.get(i).get(j) + " ";
                } else {
                    result = docArray.get(i).get(j) + " ";
                }
                doctorNameTextView.setText(result);
            }
            tableLayout.addView(row);
        }
    }

}

So How do I set the textview inside the dynamic tableview?

Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
Chris Mikkelsen
  • 3,987
  • 9
  • 29
  • 41

0 Answers0