所以我测试一个PagerView,这两个标签都不起作用。部门使用ListView,其中Facility选项卡应该显示带有可绘制图像的GridView。但是当我调试应用程序时,它们都没有出现。
这是部门片段
public class DepartmentFragment extends Fragment implements OnItemClickListener {
private ArrayList<Department> dept_list = new ArrayList<Department>();
Context context;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
context = rootView.getContext();
ListView list_view = (ListView) rootView.findViewById(R.id.dept_list);
Database database = new Database(rootView.getContext());
dept_list.addAll(Utils.SortDepartment(new ArrayList<Department>(database.getAllDepartment())));
ArrayAdapter<Department> dept_adapter = new DepartmentListAdapter(context, dept_list);
list_view.setAdapter(dept_adapter);
list_view.setOnItemClickListener(this);
return rootView;
}
//when I click on it, it shows the details page correctly
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent info_intent;
info_intent = new Intent(view.getContext(), DepartmentInfo.class);
info_intent.putExtra("deptname", dept_list.get(position).getDept_name());
startActivity(info_intent);
// TODO Auto-generated method stub
}
}
这是部门列表适配器
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Department department = this.getItem(position);
if (convertView == null) {
convertView = inflater.inflate(R.layout.dept_rowitem, null);
}
txt_deptname = (TextView) convertView.findViewById(R.id.dept_row_name);
dept_image = (ImageView) convertView.findViewById(R.id.dept_row_image);
txt_deptsummary = (TextView) convertView.findViewById(R.id.dept_row_detail);
int resID = convertView.getResources().getIdentifier(department.getDept_img(), "drawable", "com.example.yangonuniversity");
Bitmap bitmapimage = Utils.ImageDecode(resID, convertView);
dept_image.setImageBitmap(bitmapimage);
txt_deptname.setText(department.getDept_name());
txt_deptsummary.setText(Utils.unescape(department.getDept_info().substring(0, 150) + "....."));
return convertView;
}
在设施片段中
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View rootView = inflater.inflate(R.layout.fragment_build, container, false);
Database database = new Database(rootView.getContext());
build_list.addAll(database.getAllBuildings());
GridView grid_view = (GridView) rootView.findViewById(R.id.GridLayout1);
grid_view.setAdapter(new BuildingListAdapter(rootView.getContext(), build_list));
return rootView;
}
这是Facility布局中的网格视图适配器
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView img_view = new ImageView(context);
int resID = convertView.getResources().getIdentifier(build_list.get(position).getBuild_img(), "drawable", "com.example.yangonuniversity");
img_view.setImageResource(resID);
img_view.setScaleType(ScaleType.CENTER_CROP);
img_view.setLayoutParams(new GridView.LayoutParams(70, 70));
return img_view;
}
感谢您帮助我完成我的项目:D
编辑:添加图片