我在将字符串中的第一个字母转换为Capital时遇到问题:
rackingSystem.toLowerCase(); // has capitals in every word, so first convert all to lower case
StringBuilder rackingSystemSb = new StringBuilder();
rackingSystemSb.append(rackingSystem);
rackingSystemSb.setCharAt(0, Character.toUpperCase(rackingSystemSb.charAt(0)));
rackingSystem = rackingSystemSb.toString();
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用..
有什么建议?
我在 Fragment 中创建了一个自定义按钮,我试图在单击它时在 Activity 中打开导航抽屉。
当您滑动时,导航抽屉仍然可以正常打开,但是当我单击按钮时应用程序崩溃了。
我想这是因为我试图从 Fragment 访问,但我不知所措..
分段
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val binding: SiteFragmentBinding = DataBindingUtil.inflate(
inflater, R.layout.site_fragment, container, false
)
binding.apply {
siteOverflowOptionsMenuButton.setOnClickListener{
showPopUp(it)
}
siteDrawerMenuButton.setOnClickListener{
drawer_layout.openDrawer(nav_view) // this crashes (also crashes with Gravity.LEFT or similar)
}
}
return binding.root
}
Run Code Online (Sandbox Code Playgroud)
活动.xml
?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:fitsSystemWindows="true"
tools:openDrawer="start"> …Run Code Online (Sandbox Code Playgroud) 关于数据库查询的几个问题:
所以我有以下数据库查询,它有一个WHERE语句,其中包含三个String变量(rackingSystem,制造商,"Amber Risk").
public Cursor fetchComponentsAndSpecForManufacturer(long inspectionId, String rackingSystem, String manufacturer) {
Cursor mCursor =
rmDb.query(true, DAMAGED_COMPONENTS_TABLE, new String[] {
DAMAGED_COMPONENT_ID,
LOCATION_LINK,
RUN_LINK,
AREA_LINK,
INSPECTION_LINK,
LOCATION_REF,
RACKING_SYSTEM,
COMPONENT,
COMPONENT_TYPE,
QUANTITY,
POSITION,
RISK,
ACTION_REQUIRED,
NOTES_GENERAL,
MANUFACTURER,
TEXT1,
TEXT2,
TEXT3,
TEXT4,
NOTES_SPEC,
SPEC_SAVED},
INSPECTION_LINK + " = " + inspectionId + " AND " + RACKING_SYSTEM + " = ? AND " + MANUFACTURER + " = ? AND " + RISK + " = ? ",
new String[] {rackingSystem, manufacturer, "Amber …Run Code Online (Sandbox Code Playgroud) 我一直围着这个圈子走.如果它与数据库中的记录匹配,我已设法将微调器设置为显示列表中的项目,但现在在保存记录时从微调器获取所选项目时出现问题.我改为像'android.database.sqlite.SQLiteCursor@44fa41b0'.
在我的saveInspection()方法中,我使用的是inspectedBySpinner.getSelectedItem().toString(); (正如在这篇文章的第二个回答中详细说明你如何获得Spinner的选定值?)没有成功..(如此接近但没有香蕉!).
我确信这是显而易见的事情,但非常感谢:
public class InspectionEdit extends Activity {
final Context context = this;
private EditText inspectionReferenceEditText;
private EditText inspectionCompanyEditText;
private Button inspectionDateButton;
private Spinner inspectedBySpinner;
private Button saveButton;
private Button cancelButton;
protected boolean changesMade;
private AlertDialog unsavedChangesDialog;
private Button addInspectorButton;
private int mYear;
private int mMonth;
private int mDay;
private StringBuilder mToday;
private RMDbAdapter rmDbHelper;
private long inspectionId;
private String inspectedBySpinnerData;
//private String inspectors;
static final int DATE_DIALOG_ID = 0;
@Override
protected void onCreate(Bundle savedInstanceState) { …Run Code Online (Sandbox Code Playgroud) 我已经问过这个了,但是没有得到一个有效的解决方案,而且我已经对代码进行了修改.
任何人都可以帮助我,并建议为什么我的长按功能不起作用?:
public class InspectionActivity extends ListActivity {
private Button newInspection;
private static final int ACTIVITY_CREATE=0;
private RMDbAdapter rmDbHelper;
//private AlertDialog longClickOptionsDialog;
private AlertDialog clickOptionsDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inspection);
setUpViews();
rmDbHelper = new RMDbAdapter(this);
rmDbHelper.open();
// Get a Cursor for the list items
Cursor listCursor = rmDbHelper.fetchAllInspections();
startManagingCursor(listCursor);
// set the custom list adapter
setListAdapter(new MyListAdapter(this, listCursor));
}
private void setUpViews() {
newInspection = (Button)findViewById(R.id.new_inspection);
newInspection.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
createInspection();
}
}); …Run Code Online (Sandbox Code Playgroud) 我不明白为什么以下逻辑不起作用:
if (cursorCount > 1 && (!"x".equals(componentType) || !"y".equals(componentType))){
message.append("s");
}
Run Code Online (Sandbox Code Playgroud)
所以我想打印's'如果光标数超过1,但只有当componentType不等于x或y时才打印's'.
似乎适用于y但不是x有趣的案例.
Confused.com!:)
android ×5
capitalize ×1
fragment ×1
java ×1
kotlin ×1
listactivity ×1
logic ×1
long-click ×1
null ×1
where ×1