Jasonette 中的微调器
Spinner in Jasonette
我在 Jsonette 组件列表中找不到 Spinner。是否有任何替代品允许用户从列表中选择一个项目?还是应该按照 Jaonette 文档中的说明开发组件?
我找不到微调器所以自己写了(非常原始)。下面是代码:
public class JasonSpinnerComponent {
public static View build(View view, final JSONObject component, final JSONObject parent, final Context context) {
if(view == null) {
return new Spinner(context);
} else {
try {
String data = component.getString("data");
final String[] spinnerData = data.split("\|");
view = JasonComponent.build(view, component, parent, context);
JSONObject style = JasonHelper.style(component, context);
String type = component.getString("type");
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>
(context, android.R.layout.simple_spinner_item,
spinnerData);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout
.simple_spinner_dropdown_item);
((Spinner)view).setAdapter(spinnerArrayAdapter);
((Spinner)view).setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
try {
((JasonViewActivity) context).model.var.put(component.getString("name"), spinnerData[position]);
} catch (JSONException e) {
Log.e("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString());
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
((Spinner)view).requestLayout();
return view;
} catch (Exception e){
Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString());
return new View(context);
}
}
}
}
这适用于像这样的 jasonette:
{
"type": "spinner",
"name": "gender",
"data": "Male|Female"
}
我再说一遍,这是very
原始的,将来会发生很多变化。但这对于寻找微调器的人来说可能是一个很好的起点。如果对你有帮助我会很高兴
我在 Jsonette 组件列表中找不到 Spinner。是否有任何替代品允许用户从列表中选择一个项目?还是应该按照 Jaonette 文档中的说明开发组件?
我找不到微调器所以自己写了(非常原始)。下面是代码:
public class JasonSpinnerComponent {
public static View build(View view, final JSONObject component, final JSONObject parent, final Context context) {
if(view == null) {
return new Spinner(context);
} else {
try {
String data = component.getString("data");
final String[] spinnerData = data.split("\|");
view = JasonComponent.build(view, component, parent, context);
JSONObject style = JasonHelper.style(component, context);
String type = component.getString("type");
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>
(context, android.R.layout.simple_spinner_item,
spinnerData);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout
.simple_spinner_dropdown_item);
((Spinner)view).setAdapter(spinnerArrayAdapter);
((Spinner)view).setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
try {
((JasonViewActivity) context).model.var.put(component.getString("name"), spinnerData[position]);
} catch (JSONException e) {
Log.e("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString());
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
((Spinner)view).requestLayout();
return view;
} catch (Exception e){
Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString());
return new View(context);
}
}
}
}
这适用于像这样的 jasonette:
{
"type": "spinner",
"name": "gender",
"data": "Male|Female"
}
我再说一遍,这是very
原始的,将来会发生很多变化。但这对于寻找微调器的人来说可能是一个很好的起点。如果对你有帮助我会很高兴