小编Sca*_*lli的帖子

将字符串中的首字母大写

我在将字符串中的第一个字母转换为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)

这似乎不起作用..

有什么建议?

java stringbuilder capitalize

30
推荐指数
2
解决办法
3万
查看次数

从 Fragment 中的按钮单击打开导航抽屉 (Kotlin)

在 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)

android fragment kotlin navigation-drawer

4
推荐指数
1
解决办法
3506
查看次数

如何在选择中的Android数据库查询和OR语句中搜索NULL

关于数据库查询的几个问题:

所以我有以下数据库查询,它有一个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)

null android where

3
推荐指数
1
解决办法
2445
查看次数

如何在Spinner中获取所选项目

我一直围着这个圈子走.如果它与数据库中的记录匹配,我已设法将微调器设置为显示列表中的项目,但现在在保存记录时从微调器获取所选项目时出现问题.我改为像'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)

android android-spinner

2
推荐指数
1
解决办法
7187
查看次数

我无法让LongClick在ListActivity上工作

我已经问过这个了,但是没有得到一个有效的解决方案,而且我已经对代码进行了修改.

任何人都可以帮助我,并建议为什么我的长按功能不起作用?:

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)

android long-click listactivity

0
推荐指数
1
解决办法
2399
查看次数

这个逻辑语句(Android)出了什么问题?

我不明白为什么以下逻辑不起作用:

                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!:)

logic android

0
推荐指数
1
解决办法
69
查看次数