我有一个片段的布局,其中textview
内包含tableview
,我想在添加新行时设置其文本。
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);
}
}
}
那么如何在动态tableview中设置textview?