本次的练习是有关地图图层的部分,其中涉及的知识应该有ListView,滑动组件等
练习内容:
1.找到activity与xml的对应
2.自定义TextView的样式
3.有关visible invisible gone 4.获取角色属性
1.View->layer->MapLayerFrag类
@Nullable
@Override
//绑定的相关xml
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.frag_map_layer, container, false);
}
绑定的xml样式:
2.MapLayerAdapter适配器
public MapLayersAdapter() {
super();
//加载的两个类
addFullSpanNodeProvider(new GroupProvider());
addFullSpanNodeProvider(new MapProvider());
addChildClickViewIds(R.id.gis_layergroup_tv, R.id.gis_layergroup_img, R.id.gis_layergroup_check);
addChildClickViewIds(R.id.gis_layer_name, R.id.gis_layer_img, R.id.gis_layer_visibility, R.id.store, R.id.delete);
}
3.MapProvider类**
@Override
public int getLayoutId() {
return R.layout.gis_layer_childitem;
}
要求的TextView控件的代码
<TextView
android:id="@+id/txt_maptype"
android:visibility="gone"//设置为隐藏
android:layout_width="@dimen/x32"
android:layout_height="wrap_content"
android:background="@drawable/shape_textview"
android:gravity="center"
android:text="" />
xml样式
4.GroupProvider类
@Override
public int getLayoutId() {
return R.layout.gis_layer_groupitem;
}
5.UserInfo类
private String isManager = "0";//默认不是管理员
/**
* get set方法
*/
public String getIsManager() {
return isManager;
}
public void setIsManager(String isManager) {
this.isManager = isManager;
}
6.LoginActivity类
在LoginActivity中进行获取,避免后续多次获取
//检查是否是管理员
private String checkManager(String name){
String isManager = "0"; //默认非管理
//获取角色参数
String manager = MapUtilsBySqlite.getConfigValue("extraconfig","manager");
if(manager != null && manager.length() > 0) {
String[] users = manager.split(",");
for(int i=0;i<users.length;i++){
if(name.toUpperCase().equals(users[i].toUpperCase())){
isManager = "1";
break;
}
}
}
return isManager;
}
uInfo.setIsManager(checkManager(name));
7.MapProvider
UserInfo user;
if (user.getIsManager().equals("1")){
String str_type = "";
//获取type类型
String type = item.getType();
if (type!=null){
if (type.equals("tiled")){
str_type="T";
}else if(type.equals("shape")){
str_type="S";
}else if (type.equals("dynamic")){
str_type="Web";
}
}
TextView tv = (TextView) holder.getView(R.id.txt_maptype);
tv.setText(str_type);
tv.setVisibility(View.VISIBLE);//默认隐藏,设置为可见