我试图将此答案中的代码移植到Java: PHP VIN编号验证代码
据我所知,Java中的String.matches有点气质,我对正则表达式非常不熟悉.这是代码:
public boolean validateVIN(String vin) {
vin = vin.toLowerCase();
if(!vin.matches("/^[^\\Wioq]{17}$/")) { //the offending code, always fails
Log.e("vininfo", "did not pass regex");
return false;
}
int[] weights = { 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 };
//array positions coorespond to the 26 letters of the alphabet
int[] transliterations = { 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 0, 7, 0, …Run Code Online (Sandbox Code Playgroud) 我有一个CursorAdapter是从数据库构建的Cursor,如果View第一个项目中没有填写,它会填充第一个项目的Views,View其中包含View设置的第一个后续列表项中的数据.另外,我发现onBindView每个列表项都会触发三次,这看起来很奇怪.它只对第一个列表项执行此操作,而不是对所有具有null Views 的项执行此操作.这是它的样子:

请注意,"Julian"的地址已复制到"Alice".每当我在onBindView方法中设置一个断点时,我可以看到当customerName是"Alice Martin"时,if(billingAddressCursor!=null && billingAddressCursor.getCount()>0)对于所有三次调用,总是评估为false onBindView,所以我知道它永远不会进入计费条件.
为什么它在第一个位置绘制错误的值并且如何阻止它?码:
private class CustomerAdapter extends CursorAdapter {
/*** DEBUG CODE, TO BE REMOVED ***/
int aliceBindCount = 0;
int blakeBindCount = 0;
int cscBindCount = 0;
int julianBindCount = 0;
/*** ^^^^^^^^^^^^^^^^^^^^^^^^^ ***/
public CustomerAdapter(Context context, Cursor cursor) {
super(context, cursor);
}
public void bindView(View convertView, Context context, Cursor cursor) {
if(convertView!=null) {
String …Run Code Online (Sandbox Code Playgroud) 我究竟做错了什么?我得到一个没有内容的空白对话框.码:
@Override
protected Dialog onCreateDialog(int id, Bundle b) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(this.LAYOUT_INFLATER_SERVICE);
switch(id) {
case DIALOG_COLOR_MODE:
{
LinearLayout layout = new LinearLayout(this);
LinearLayout.LayoutParams lllp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layout.setLayoutParams(lllp);
ListView modeList = new ListView(this);
Dialog dialog = new Dialog(this);
TextView layoutBright = new TextView(this);
TextView layoutNormal = new TextView(this);
layoutBright.setText("Bright Mode");
layoutNormal.setText("Normal Mode");
modeList.addFooterView(layoutBright);
modeList.addFooterView(layoutNormal);
layout.addView(modeList);
dialog.setContentView(layout);
return dialog;
}
[...]
Run Code Online (Sandbox Code Playgroud) 我有一个布局,我需要完整滚动.布局包含一个列表视图底部,这导致一些不和谐.这是发生了什么:

所以你可以看到底部在它自己的小世界中滚动,我需要禁用它,以便它增长并扩展整个布局以进行滚动.我已经尝试将它全部封装在一起<scrollview><linearlayout>mystuff</linearlayout></scrollview>,但无济于事.我尝试过无限组合"match_parent"和"wrap_content" layout_heights.我真的需要listview在没有将自己置于自己的滚动世界的情况下向外扩展.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow>
<TableLayout android:layout_span="2"
android:layout_width="fill_parent"
android:layout_weight="1">
<TableRow android:gravity="center">
<Button android:id="@+id/vin_btn"
android:width="@dimen/inb_btn_w"
android:height="@dimen/inb_btn_h"
android:text="@string/inb_vin_btn"
android:textSize="@dimen/inb_txt_sz" />
<Button android:id="@+id/clear_btn"
android:width="@dimen/inb_btn_w"
android:height="@dimen/inb_btn_h"
android:text="@string/inb_sc_btn"
android:textSize="@dimen/inb_txt_sz" />
<Button android:id="@+id/transmit_btn"
android:width="@dimen/inb_btn_w"
android:height="@dimen/inb_btn_h"
android:text="@string/inb_tr_btn"
android:textSize="@dimen/inb_txt_sz"/>
</TableRow>
</TableLayout>
</TableRow>
<TableRow android:gravity="center_vertical"
android:layout_width="fill_parent">
<TextView
android:gravity="right"
android:id="@+id/text_cust"
android:textSize="@dimen/inb_txt_sz"
android:text="@string/inb_cust"/>
<Spinner
android:layout_width="fill_parent"
android:layout_weight="1"
android:id="@+id/cust_spn"/>
</TableRow>
<TableRow android:layout_width="fill_parent">
<TextView
android:gravity="right"
android:id="@+id/text_drv"
android:textSize="@dimen/inb_txt_sz"
android:text="@string/inb_drv"/>
<EditText
android:id="@+id/drv_in"
android:inputType="number"
android:layout_width="fill_parent"
android:layout_weight="1"
android:singleLine="true"/>
</TableRow>
<TableRow …Run Code Online (Sandbox Code Playgroud)