我想创建一个非常简单的游标自定义游标适配器,以方便在点击时更改行项目的颜色.使用以下代码
private static int save = -1;
public void onListItemClick(ListView parent, View v, int position, long id) {
parent.getChildAt(position).setBackgroundColor(Color.BLUE);
if (save != -1 && save != position){
parent.getChildAt(save).setBackgroundColor(Color.BLACK);
}
save = position;
}
Run Code Online (Sandbox Code Playgroud)
我从这个线程获得了代码/sf/answers/535491631/
我会使用一个简单的游标适配器并将代码放在onClick中,但由于ListFragment中的默认列表重用了视图,因此滚动多个视图时会突出显示.谈到IRC,有人建议我创建一个自定义游标适配器.但是,我似乎无法找到如何执行此操作的最佳实践,以及上述代码段所适用的位置.可以非常感谢帮助.
public class AreaCursorAdapter extends CursorAdapter {
private Context context;
public AreaCursorAdapter(Context context, Cursor c) {
super(context, c);
// TODO Auto-generated constructor stub
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView list_item = (TextView)view.findViewById(android.R.id.text1);
list_item.setText(cursor.getString(cursor.getColumnIndex(INDICATOR_NAME)));
}
@Override
public View newView(Context context, …Run Code Online (Sandbox Code Playgroud) android android-listview simplecursoradapter android-listfragment android-cursoradapter
我试图基于HTTP get变量中包含的变量动态更新表单字段.特别是www.site.com/form?id=name.我想从url中提取'id'字段并自动填充表单的memberID字段.
我可以使用self.request.get('id')访问get变量.但是我无法弄清楚如何更新表单字段.我检查了小部件文档http://packages.python.org/z3c.form/widget.html,但没有一个建议有效.
class IUpdateEmailFormSchema(interface.Interface):
# -*- extra stuff goes here -*-
"""
"""
memberID = schema.TextLine(title=(u'Member id'))
email = schema.TextLine(title=(u'Email'), description=(u'The email'))
class updateEmailForm(form.Form):
fields = field.Fields(IUpdateEmailFormSchema)
label = _(u'Change Email')
ignoreContext = True
@button.buttonAndHandler(u'Update')
def handleUpdate(self,action):
data, errors = self.extractData()
if data.has_key('email'):
portal_membership = getToolByName(self.context, 'portal_membership')
member = portal_membership.getMemberById(data['memberID'])
def updateWidgets(self):
print "This is update widget \n\n"
import pdb; pdb.set_trace()
print self.request.form['id'] #Does not work as specified in http://packages.python.org/z3c.form/widget.html
#self.widgets["memberID"].value = self.request.get('id').encode('utf-8')
form.Form.updateWidgets(self)
updateEmailFormView = wrap_form(updateEmailForm) …Run Code Online (Sandbox Code Playgroud)