- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
按 AutoCompleteTextView 上软键盘上的下一个按钮(无论是否输入数据),我尝试将焦点更改到下一个 EditText 并保留软键盘。焦点发生变化,但软键盘消失。我尝试使用 InputMethodManager 但无济于事。我正在做的事情有什么根本不正确的地方吗?
public class AuthorizeLoadActivity extends AppCompatActivity {
TextView operatorNameValue;
ImageButton cameraButton;
TextView ticketNumberValue;
TextView saleNameValue;
Spinner haulerSpinner;
Spinner saleProductSpinner;
Spinner destinationSpinner;
AutoCompleteTextView driverAutoCompleteTextView;
EditText trailerEditText;
Spinner trailerDropSpinner;
Button cancelButton;
Button saveAuthorizationButton;
Button addACommentButton;
String barcodeValue;
ArrayList<SaleObject> savedArrayList;
SaleObject currentSaleObject;
ArrayList<String> haulerNameArrayList = new ArrayList<>();
ArrayList<String> saleProductNameArrayList = new ArrayList<>();
ArrayList<Integer> haulerIDArrayList = new ArrayList<>();
ArrayList<Integer> saleProductIDArrayList = new ArrayList<>();
ArrayList<String> destinationArrayList = new ArrayList<>();
ArrayList<AuthorizationObject> authorizationArrayList = new ArrayList<>();
ArrayList<String> driverArrayList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_authorizeload);
//link instance of menu_main
Toolbar mainToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mainToolbar);
//Enable Up Button to return you to home page
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
barcodeValue = getIntent().getStringExtra("barcodeValue");
//Link UI to XML
operatorNameValue = findViewById(R.id.operatorNameValue);
cameraButton = findViewById(R.id.cameraButton);
ticketNumberValue = findViewById(R.id.ticketNumberValue);
saleNameValue = findViewById(R.id.saleNameSpinner);
haulerSpinner = findViewById(R.id.ticketNumberTextView);
saleProductSpinner = findViewById(R.id.saleProductSpinner);
destinationSpinner = findViewById(R.id.buyerSpinner);
driverAutoCompleteTextView = findViewById(R.id.driverAutoComplete);
trailerEditText = findViewById(R.id.trailerNumberEditText);
trailerDropSpinner = findViewById(R.id.trailerDropSpinner);
cancelButton = findViewById(R.id.cancelButton);
saveAuthorizationButton = findViewById(R.id.saveLoadButton);
addACommentButton = findViewById(R.id.addACommentButton);
//set Security Number Value to barcode information previously collected
ticketNumberValue.setText(barcodeValue);
//Reduce EditText/AutoCompleteTextView text sizes if using phone rather than tablet
boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (!tabletSize) {
driverAutoCompleteTextView.setTextSize(10);
trailerEditText.setTextSize(10);
}
//Check files for existent drivers and pull them back into an ArrayList
//Check internal storage for driver data
try {
//Set target file to drivers.txt
File targetFile = new File(getFilesDir(), "drivers.txt");
//Create new file input stream
FileInputStream fis = new FileInputStream(targetFile);
//Create new object input stream, using fis
ObjectInputStream ois = new ObjectInputStream(fis);
//write object input stream to object
//noinspection unchecked
driverArrayList = (ArrayList<String>) ois.readObject();
//close object output stream
ois.close();
//close file output stream
fis.close();
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
//Setup autoCompleteTextView list with drivers
ArrayAdapter<String> driverAdapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, driverArrayList);
driverAutoCompleteTextView.setAdapter(driverAdapter);
//show AutoComplete information without having to type first.
driverAutoCompleteTextView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
driverAutoCompleteTextView.showDropDown();
} else {
driverAutoCompleteTextView.dismissDropDown();
}
}
});
//move to next editText when soft keyboard next button is pressed.
driverAutoCompleteTextView.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// remove focus from driverAutoCompleteTextView
driverAutoCompleteTextView.clearFocus();
// give focus to trailerEditText
trailerEditText.setFocusableInTouchMode(true);
trailerEditText.requestFocus();
showKeyboard(trailerEditText);
return true;
}
return false;
}
});
//Initiate the barcode reader to replace security number value field
cameraButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
saveAuthorizationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (haulerSpinner.getSelectedItemPosition() != 0 && saleProductSpinner.getSelectedItemPosition() != 0 && destinationSpinner.getSelectedItemPosition() != 0 && !driverAutoCompleteTextView.getText().toString().equals("") && !trailerEditText.getText().toString().equals("")) {
//Get all of the pertinent data
String currentOperatorID = currentSaleObject.getlbOperatorID();
String currentSaleName = currentSaleObject.getTimberSaleName();
Integer currentTimberSaleID = currentSaleObject.getTimberSaleID();
Integer currentProductID = saleProductIDArrayList.get(saleProductSpinner.getSelectedItemPosition());
String currentProductName = saleProductNameArrayList.get(saleProductSpinner.getSelectedItemPosition());
Integer currentHaulerID = haulerIDArrayList.get(haulerSpinner.getSelectedItemPosition());
String currentHaulerName = haulerNameArrayList.get(haulerSpinner.getSelectedItemPosition());
String currentDestination = destinationArrayList.get(destinationSpinner.getSelectedItemPosition());
String currentDriver = driverAutoCompleteTextView.getText().toString();
String currentTrailerNumber = trailerEditText.getText().toString();
Boolean currentTrailerDrop = trailerDropSpinner.getSelectedItemPosition() != 0;
//If new driver, add driver name to drivers.text
Boolean driverAlreadyExists = false;
for (int i = 0; i < driverArrayList.size(); i++) {
if (driverArrayList.get(i).equals(currentDriver)) {
driverAlreadyExists = true;
}
}
if (!driverAlreadyExists) {
//add new driver to driverArrayList
driverArrayList.add(currentDriver);
//write driver list back to drivers.txt
try {
//Set target file to drivers.txt
File targetFile = new File(getFilesDir(), "drivers.txt");
//Create new file output stream
FileOutputStream fos = new FileOutputStream(targetFile);
//Create new object output stream, using fos
ObjectOutputStream oos = new ObjectOutputStream(fos);
//write object to object output stream
oos.writeObject(driverArrayList);
//close object output stream
oos.close();
//close file output stream
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//Get GPS values
LocationManager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
double[] gpsValues = getLastBestLocation(mLocationManager);
//if GPS data exists...
if (gpsValues != null) {
double currentLatitude = gpsValues[0];
double currentLongitude = gpsValues[1];
//Create an authorization object with the data
AuthorizationObject currentAuthorization = new AuthorizationObject(currentOperatorID, currentTimberSaleID, currentSaleName, currentProductID, currentProductName, currentHaulerID, currentHaulerName, ticketNumberValue.getText().toString(), currentDestination, currentDriver, currentTrailerNumber, currentTrailerDrop, currentLatitude, currentLongitude);
//Check files for existent authorizations and pull them back as AuthorizationObjects
//Check internal storage for authorization data
try {
//Set target file to authorizations.txt
File targetFile = new File(getFilesDir(), "authorizations.txt");
//Create new file input stream
FileInputStream fis = new FileInputStream(targetFile);
//Create new object input stream, using fis
ObjectInputStream ois = new ObjectInputStream(fis);
//write object input stream to object
//noinspection unchecked
authorizationArrayList = (ArrayList<AuthorizationObject>) ois.readObject();
//close object output stream
ois.close();
//close file output stream
fis.close();
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
//add authorization to authorizationArrayList
authorizationArrayList.add(currentAuthorization);
//write authorization list back to authorizations.txt
try {
//Set target file to authorizations.txt
File targetFile = new File(getFilesDir(), "authorizations.txt");
//Create new file output stream
FileOutputStream fos = new FileOutputStream(targetFile);
//Create new object output stream, using fos
ObjectOutputStream oos = new ObjectOutputStream(fos);
//write object to object output stream
oos.writeObject(authorizationArrayList);
//close object output stream
oos.close();
//close file output stream
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
Intent authorizeLoadToMainIntent = new Intent(AuthorizeLoadActivity.this, MainActivity.class);
authorizeLoadToMainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(authorizeLoadToMainIntent);
} else {
//TODO: Build better GPS permissions thing.
Toast.makeText(AuthorizeLoadActivity.this, "Must allow location permissions", Toast.LENGTH_SHORT).show();
}
} else {
//TODO: Build more robust error-handling than just a toast.
Toast.makeText(AuthorizeLoadActivity.this, "Fill out all fields", Toast.LENGTH_SHORT).show();
}
}
});
addACommentButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
//Check internal storage for sale data
try {
//Set target file to sales.txt
File targetFile = new File(getFilesDir(), "sales.txt");
//Create new file input stream
FileInputStream fis = new FileInputStream(targetFile);
//Create new object input stream, using fis
ObjectInputStream ois = new ObjectInputStream(fis);
//write object input stream to object
//noinspection unchecked
savedArrayList = (ArrayList<SaleObject>) ois.readObject();
//close object output stream
ois.close();
//close file output stream
fis.close();
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
//Start off with non-values in the spinners so I can ensure that users actually interacted with them
haulerNameArrayList.add("");
saleProductNameArrayList.add("");
haulerIDArrayList.add(0);
saleProductIDArrayList.add(0);
destinationArrayList.add("");
//Get range values to check against entered (or scanned) string
for (int i = 0; i < savedArrayList.size(); i++) {
ArrayList<RangeObject> currentSaleObjectRanges = savedArrayList.get(i).getRanges();
for (int j = 0; j < currentSaleObjectRanges.size(); j++) {
RangeObject currentRange = currentSaleObjectRanges.get(j);
Integer startValue = currentRange.getStart();
Integer endValue = currentRange.getEnd();
//Check if editText string is an Integer
try {
Integer editTextInteger = Integer.parseInt(barcodeValue);
//If it is:
//If editTextInteger falls between the two of the range:
if (editTextInteger >= startValue && editTextInteger <= endValue) {
currentSaleObject = savedArrayList.get(i);
//Set UI elements to correspond with current sale info.
operatorNameValue.setText(currentSaleObject.getLbOperatorName());
saleNameValue.setText(currentSaleObject.getTimberSaleName());
//Create ArrayList for contract objects and get all of their information.
//Essentially iterates through all contracts of currentSaleObject and creates an arrayList of contracts.
//This (single next line) was auto-generated by Android Studio. Was a for loop.
ArrayList<ContractObject> contractArrayList = new ArrayList<>(currentSaleObject.getContract());
//iterate through contractArrayList and get the values for the different fields
for (int k = 0; k < contractArrayList.size(); k++) {
ContractObject currentContract = contractArrayList.get(k);
haulerNameArrayList.add(currentContract.getHaulerName());
saleProductNameArrayList.add(currentContract.getSaleProductName());
haulerIDArrayList.add(currentContract.getHaulerID());
saleProductIDArrayList.add(currentContract.getSaleProductID());
destinationArrayList.add(currentContract.getDestinationName());
}
//remove duplicates in each arrayList for spinners
HashSet<String> haulerNameHashSet = new HashSet<>(haulerNameArrayList);
haulerNameArrayList.clear();
haulerNameArrayList.addAll(haulerNameHashSet);
HashSet<Integer> haulerIDHashSet = new HashSet<>(haulerIDArrayList);
haulerIDArrayList.clear();
haulerIDArrayList.addAll(haulerIDHashSet);
HashSet<String> productNameHashSet = new HashSet<>(saleProductNameArrayList);
saleProductNameArrayList.clear();
saleProductNameArrayList.addAll(productNameHashSet);
HashSet<Integer> productIDHashSet = new HashSet<>(saleProductIDArrayList);
saleProductIDArrayList.clear();
saleProductIDArrayList.addAll(productIDHashSet);
HashSet<String> destinationHashSet = new HashSet<>(destinationArrayList);
destinationArrayList.clear();
destinationArrayList.addAll(destinationHashSet);
//Set spinner values
//set simple adapters for spinners
ArrayAdapter<String> haulerSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, haulerNameArrayList);
haulerSpinner.setAdapter(haulerSpinnerAdapter);
ArrayAdapter<String> saleProductSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, saleProductNameArrayList);
saleProductSpinner.setAdapter(saleProductSpinnerAdapter);
ArrayAdapter<String> destinationSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, destinationArrayList);
destinationSpinner.setAdapter(destinationSpinnerAdapter);
//autofill spinner value if only one value is left after removing duplicates.
if (haulerNameArrayList.size() == 2) {
haulerSpinner.setSelection(1);
}
if (saleProductNameArrayList.size() == 2) {
saleProductSpinner.setSelection(1);
}
if (destinationArrayList.size() == 2) {
destinationSpinner.setSelection(1);
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
}
private void showKeyboard(View view) {
InputMethodManager manager = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE);
manager.showSoftInput(view, 0);
}
//add action items to toolbar
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
//add action item functionality
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_filter:
// User chose the filter item, do stuff...
return true;
case R.id.action_first:
// User chose the first item, do stuff...
return true;
case R.id.action_second:
// User chose the second item, do stuff...
return true;
case R.id.action_third:
// User chose the third item, do stuff...
return true;
default:
// If we got here, the user's action was not recognized.
// Invoke the superclass to handle it.
return super.onOptionsItemSelected(item);
}
}
//Used to bring over scan information from the barcode reader
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanningResult != null) {
//set scanned data to security number value
barcodeValue = scanningResult.getContents();
ticketNumberValue.setText(barcodeValue);
} else {
Toast toast = Toast.makeText(getApplicationContext(),
"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
private double[] getLastBestLocation(LocationManager mLocationManager) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling this to handle no GPS permissions
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
Toast.makeText(this, "You don't have location permissions enabled", Toast.LENGTH_SHORT).show();
return null;
} else {
Location locationGPS = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Location locationNet = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
long GPSLocationTime = 0;
if (null != locationGPS) {
GPSLocationTime = locationGPS.getTime();
}
long NetLocationTime = 0;
if (null != locationNet) {
NetLocationTime = locationNet.getTime();
}
if (0 < GPSLocationTime - NetLocationTime) {
if (locationGPS != null) {
return new double[]{locationGPS.getLatitude(), locationGPS.getLongitude()};
} else {
return null;
//TODO: Handle nulls, here.
}
} else {
if (locationNet != null) {
return new double[]{locationNet.getLatitude(), locationNet.getLongitude()};
} else {
return null;
//TODO: Handle nulls, here.
}
}
}
}
}
最佳答案
如果您希望显示软键盘,请执行此操作
driverAutoCompleteTextView.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// remove focus from driverAutoCompleteTextView
driverAutoCompleteTextView.clearFocus();
// give focus to trailerEditText
trailerEditText.setFocusable(true);
trailerEditText.setFocusableInTouchMode(true);
boolean isFocused = trailerEditText.requestFocus();
Log.d("myTag","isFocused is: "+isFocused);
Log.d("myTag","driver auto complete text view focused: "+driverAutoCompleteTextView.isFocused());
showKeyboard(trailerEditText);
return true;
}
return false;
}
});
private void showKeyboard(View view){
InputMethodManager manager = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE);
manager.showSoftInput(view,InputMethodManager.SHOW_IMPLICIT);
}
这虽然又快又脏,但应该可以工作。另外,您应该在 onCreate 方法或 xml 中添加 TrailerEditText.setFocusableInTouchMode(true)。
关于java - 当焦点从 AutoCompleteTextView 更改为 EditText 时,软键盘不会持续存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53339902/
如果我错了,但身份验证 session 有 30 天的最大限制,请纠正我?如果是这种情况,有没有办法让我的服务器节点应用程序永远监听经过身份验证的 dataRef? 干杯, 旅行。 最佳答案 自 on
我目前正在阅读 book Continuos Delivery由 Humble/Farley 撰写,虽然里面的很多东西都是有道理的,但有一件事让我烦恼: 似乎作者只针对基于服务器的(单客户端?)应用程
好吧,我非常了解每个人对自制密码管理器的看法,但我希望得到帮助。 不用于实际使用,仅供学习。 我想知道,在 C++ 中如何拥有长期变量。或者真的,有什么长期的。 长期是什么意思?在下次运行 .exe
我在文本文件中有以下三行(最后 3 行): } } } 我想做的是做这样的事情: } } blablabla blablabla blabla
在 iOS 中,有没有一种简单的方法可以在每天的同一时间发送 10 天的推送通知?我不想向所有用户发送推送通知。我的应用程序的工作方式是,用户可以选择连续十天推送通知的时间。您有推荐的 API 吗?或
我正在努力寻找一种当前最先进的方法来处理频繁更新的通知(例如每 3 分钟一次)。似乎在较新的 Android 版本中内置了如此多的电源效率调整(幸运的是!),我之前成功使用的方法(使用 Broadca
我不得不在一些糟糕的房地产网站上花费大量时间。我比较精通 CSS,并且可以(在 FireFox 中)“检查元素”并更改 CSS 以隐藏或缩小特定页面的华而不实的元素。但我想将此自定义 CSS 应用于特
目前正在研究如何使用 signalR 在处理文件时向用户呈现文件的进度报告。我正在使用 asp.net MVC 4。通过 Ajax 进行发布/获取时,我可以轻松获取状态更改。 因为我需要上传一个文件(
这个问题在这里已经有了答案: How can I round up the time to the nearest X minutes? (15 个答案) Is there a simple fun
我有一个 php 脚本,我想运行特定的时间(例如 5 分钟),但只能运行一次。对于 cron 作业,这将无限期地运行。还有别的办法吗? 最佳答案 处理这个问题的方法是: 当某些事件触发需要 cron
我弄乱了我的 apache 和 php.ini 文件,我网站的用户仍然提示该网站在很短的时间后或每次他们关闭并打开同一个浏览器时将他们注销。 我正在运行 Apache 和 PHP。 我应该进行哪些设置
如何查询今天的总和需要减去前一天的总和,每天持续一个月。 SELECT COUNT(DISTINCT member_profile.memberProfileNumber) FROM member_p
这个问题在这里已经有了答案: How do I add a delay in a JavaScript loop? (32 个答案) 关闭 8 年前。 我认为这个问题之前一定有人问过,但我找不到其他
用户在我的网站上注册后,我们会向他发送一封确认电子邮件。我想要的是 - 三天内每 24 小时为用户重新发送一次电子邮件。例如: user_table id , name, date_registere
最近我从 Codeigniter 换到了 Laravel,一切都很顺利,除了我遇到了 Session::flash 的问题。 当我创建新用户时,我收到成功消息,但它会持续 2 个请求,即使我没有通过验
如果有人能帮助我解决这个问题,我将非常感激。 我正在尝试针对 CPU 使用率 >= 80% 持续 30 分钟或更长时间创建 Azure 监视器警报 我已附上警报规则条件的屏幕截图。在“评估依据”下,聚
如果有人能帮助我解决这个问题,我将非常感激。 我正在尝试针对 CPU 使用率 >= 80% 持续 30 分钟或更长时间创建 Azure 监视器警报 我已附上警报规则条件的屏幕截图。在“评估依据”下,聚
希望大家平安 1。我的目标 我正在尝试模拟 3 天的真实情况。系统每天只能工作 8 小时。 我的目标是模型运行 8 小时,持续 3 天,以获得足够的数据进行分析。 2。我的问题 我有一个代理预约时间表
我需要在 8 小时内每 5 分钟调用一次函数。问题是它必须是同一天。例如,如果用户在 3/29 晚上 11:59 登录系统,而现在是 3/30 凌晨 12:01,则不应再调用该函数。 我知道如何每
我正在开发一个 React Native 应用程序,该应用程序使用 Firebase 的 Firestore 作为后端。现在,每次收到新消息时,我都会从 Firestore 获取所有消息并更新我的状态
我是一名优秀的程序员,十分优秀!