-
jiayu.lin说:
android Preference 怎么设置selector,用code
实现
//设置Seletor
ListPreference listPreference = (ListPreference)findPreference("list_preference_key");
listPreference.setEntries(R.array.list_preference_entries);
listPreference.setEntryValues(R.array.list_preference_entry_values);
listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
//TODO
return true;
}
}); -
jiayu.lin说:
android ListPreference 怎么设置selector,用code
可以使用ListPreference的setEntries和setEntryValues方法来设置selector:
ListPreference listPreference = (ListPreference) findPreference("list_preference");
String[] entries = new String[] {"Option 1", "Option 2", "Option 3"};
String[] entryValues = new String[] {"1", "2", "3"};listPreference.setEntries(entries);
listPreference.setEntryValues(entryValues); -
gao55pan说:
请用FastAPI-Amis-Admin 实现学生列表信息管理,给出具体实现代码
# -*- coding: utf-8 -*- from fastapi import FastAPI from amis_admin import AmisAdmin app = FastAPI() admin = AmisAdmin(app) @admin.register() def student_list(): schema = { "type": "page", "title": "学生管理", "body": { "type": "crud", "name": "student_list", "controls": [ { "name": "name", "type": "input", "label": "姓名" }, { "name": "age", "type": "number", "label": "年龄" }, { "name": "gender", "type": "select", "label": "性别", "source": [ { "name": "男", "value": "male" }, { "name": "女", "value": "female" } ] }, { "name": "phone", "type": "input", "label": "电话" }, { "name": "address", "type": "input", "label": "地址" } ], "dataSource": { "type": "mock", "data": [ { "name": "张三", "age": 20, "gender": "male", "phone": "123456789", "address": "北京市朝阳区" }, { "name": "李四", "age": 25, "gender": "female", "phone": "987654321", "address": "上海市浦东新区" } ] } } } return schema
-
gao55pan说:
请用FastAPI+FastAPI-Amis-Admin 实现学生信息管理,给出具体实现代码
FastAPI实现
from fastapi import FastAPI, Body from fastapi.encoders import jsonable_encoder from pydantic import BaseModel app = FastAPI() # 定义学生信息实体类 class StudentInfo(BaseModel): name: str age: int gender: str # 定义学生信息字典,用于模拟数据库 students = {} # 添加学生信息(POST) @app.post("/students/") async def add_student(student: StudentInfo): student_id = len(students) student_dict = student.dict() student_dict["id"] = student_id students[student_id] = student_dict return student_dict # 修改学生信息(PUT) @app.put("/students/{student_id}") async def update_student(student_id: int, student: StudentInfo): student_dict = student.dict() student_dict["id"] = student_id students[student_id] = student_dict return student_dict # 查询学生信息(GET) @app.get("/students/{student_id}") async def get_student(student_id: int): return students.get(student_id) # 删除学生信息(DELETE) @app.delete("/students/{student_id}") async def delete_student(student_id: int): students.pop(student_id) return student_id
FastAPI-Amis-Admin实现
from fastapi import FastAPI from amis_admin import AmisAdmin app = FastAPI() # 定义学生信息Amis配置 student_admin = AmisAdmin( name="学生信息", description="学生信息的管理", menus=[ { "label": "学生列表", "path": "/students", "component": "PageList", "api": { "url": "/students", "method": "get", "data": { "type": "json" } } }, { "label": "添加学生", "path": "/students/add", "component": "PageForm", "api": { "url": "/students", "method": "post", "data": { "type": "json" } }, "props": { "mode": "create", "schema": [ { "name": "name", "label": "姓名", "type": "text" }, { "name": "age", "label": "年龄", "type": "number" }, { "name": "gender", "label": "性别", "type": "text" } ] } }, { "label": "修改学生", "path": "/students/:id/edit", "component": "PageForm", "api": { "url": "/students/:id", "method": "put", "data": { "type": "json" } }, "props": { "mode": "edit", "schema": [ { "name": "name", "label": "姓名", "type": "text" }, { "name": "age", "label": "年龄", "type": "number" }, { "name": "gender", "label": "性别", "type": "text" } ] } } ] ) # 注册Amis路由 app.include_router(student_admin.get_router(), prefix="/admin")