XML
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="600dp"
android:id="@+id/ly2"
android:orientation="vertical"
tools:ignore="MissingConstraints">
<LinearLayout
android:orientation="vertical"
android:id="@+id/ly1"
android:layout_width="match_parent"
android:layout_height="150dp"
tools:ignore="MissingConstraints">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="条码"
android:imeOptions="actionNext"
android:nextFocusForward="@+id/password"
/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="密码"
android:inputType="textPassword" />
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="清理库存"></Button>
</LinearLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<ListView
android:id="@+id/list_viewstockbill"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</HorizontalScrollView>
</LinearLayout>
Activity
EditText password;
ListView listView;
private void ValLoginWindow() {
try {
list = new ArrayList<>();
for (int i= 0 ;i < 3;i++){
OutDeport outDeport = new OutDeport();
outDeport.setWis_BatchNo("物料批号");
outDeport.setWis_DateCode("DateCode");
list.add(outDeport);
}
final View v = getLayoutInflater().inflate(R.layout.tab_view, null);
listView = v.findViewById(R.id.list_viewstockbill);
adapter = new DialogStockBillAdapter(this, R.layout.dialog_list_del,list );
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final OutDeport outDeport = list.get(position);
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("提示:");
dialog.setMessage("是否删除?");
dialog.setCancelable(false);
dialog.setPositiveButton("是", new DialogInterface.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onClick(DialogInterface dialog, int which) {
list.clear();
adapter.notifyDataSetChanged();
}
});
dialog.setNegativeButton("否", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.show();
}
});
final EditText username = v.findViewById(R.id.username);
username.requestFocus();
password = v.findViewById(R.id.password);
username.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (keyEvent.getAction() == KeyEvent.KEYCODE_BACK) {
finish();
} else if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
return true;
} else if (i == KeyEvent.KEYCODE_ENTER) {
Toast.makeText(MainActivity.this,"你点击了回车",Toast.LENGTH_SHORT).show();
password.setCursorVisible(true);
password.requestFocus();
return true;
}
return false;
}
});
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setView(v);
builder.setPositiveButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
builder.setNegativeButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
WindowManager.LayoutParams wlp = dialog.getWindow().getAttributes();
wlp.gravity = Gravity.TOP | Gravity.LEFT;
wlp.x = 10;
wlp.y = 10;
dialog.show();
dialog.getWindow().setLayout(400, 700);
} catch (Exception e) {
e.printStackTrace();
}
}
这个页面是一个按钮弹出的弹出框页面,然后我想条码输入完回车之后光标聚焦在密码位置,结果光标在密码框一闪而过,就聚焦到按钮上面了.怎么回事啊!