只是我不明白背后的全部意义.我知道如果我想使用正则表达式找到它们,我需要逃避任何特殊含义字符.而且我还读到了某些地方,如果它在String文字中,你需要逃避Java中的反斜杠.我的问题是,如果我"逃避"反斜杠,它不会失去意义吗?那么它将无法逃脱以下加号?
引发错误(但不应该有效,因为这是你如何逃避这些特殊字符?):
replaceAll("\+\s", ""));
Run Code Online (Sandbox Code Playgroud)
作品:
replaceAll("\\+\\s", ""));
Run Code Online (Sandbox Code Playgroud)
希望这是有道理的.我只是想了解我为什么需要这些额外斜线的功能,因为我读过的正则表达式教程没有提到它们.这样的事情"\+"应该找到加号.
好的,让我们看看我能解释一下我的意思,这里有一个图片可以帮助:

因此,正如您在图像中看到的那样,我需要将绿色箭头从其当前位置放置到位于保持它的主div之外.我需要这样,如果页面重新调整大小,箭头将保持在其位置.如果您需要更多信息,请告诉我.对不起,如果这太模糊,我不知道如何解释它.谢谢!
因此,当我添加一个项目时,它不会为其设置动画,也不会滚动到正确的位置.但是,当我删除某些内容时,它将为对象移除设置动画.
这是添加代码:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == NEWITEMREQUESTCODE && resultCode == Activity.RESULT_OK) {
// AFTER CREATING A NEW ITEM
OilChangeableItem oilChangeableItem = data.getParcelableExtra("oil_item");
// Add the new item and notify the dataset.
oilChangeableAdapter.notifyItemInserted(0);
items.add(0, oilChangeableItem);
} else if (requestCode == EDITITEMRESULTCODE && resultCode == Activity.RESULT_OK) {
// AFTER EDITING AN ITEM
OilChangeableItem oilChangeableItem = data.getParcelableExtra("oil_item");
// Replace the existing item at whatever position it was originally at and notify the …Run Code Online (Sandbox Code Playgroud) 因此,出于某种原因,每当我向ArrayList添加一个新项目并通知recyclelerview它已被添加时,它就会复制先前条目的数据.因此,视图会被创建,但最后一个条目的数据不是当前数据.
奇怪的是,我使用ORM Sugar保存项目,因此当我检索它们时,会显示正确的数据.这表明数据已添加但视图未正确显示.
我只能假设每当我使用notifyItemInserted方法时,recyclerview都没有调用onBindViewHolder,因为当我使用notifyDataSetChange()时会显示正确的数据
这是我添加新项目的方法
@Override
public void AddCalorieToHistoryList(int calorieAmount, int currentCalorieAmount) {
// Get the date and the calorie amount from what the user entered.
Date date = new Date();
// Create the calorie history item and then save it (via ORM Sugar Library)
CalorieHistory calorieHistory = new CalorieHistory(date.toString(), calorieAmount);
calorieHistory.save();
// Notify the view of the new item that should be inserted.
historyView.InsertNewListItem(calorieHistory);
SubtractFromCurrentCalorieAmount(calorieAmount, currentCalorieAmount);
}
Run Code Online (Sandbox Code Playgroud)
historyView的方法
@Override
public void InsertNewListItem(CalorieHistory calorieHistoryItem) {
// Add the new …Run Code Online (Sandbox Code Playgroud) 因此,无论何时这两条线被评论出来都很好,但是随着它们的崩溃.
EditText convertValue = (EditText) findViewById(R.id.et_value_convert);
TextView convertResult = (TextView) findViewById(R.id.txt_result);
Run Code Online (Sandbox Code Playgroud)
这是我的完整类代码,xml在下面.
package com.doubleelite.maxtest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class ConverterActivity extends Activity {
EditText convertValue = (EditText) findViewById(R.id.et_value_convert);
TextView convertResult = (TextView) findViewById(R.id.txt_result);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_converter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_converter, menu);
return true;
}
// Custom method …Run Code Online (Sandbox Code Playgroud) 这是我的 DroidArmoryActivity 代码
package com.maxgenero.droidarmory;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class DroidArmoryActivity extends Activity implements View.OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()) {
case R.id.ibM4A1:
Intent intentM4A1 = new Intent("com.maxgenero.droidarmory.M4A1GUN");
startActivity(intentM4A1);
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
它根本没有启动java文件(活动),没有错误。顺便说一句,这个案例正在寻找一个 imageButton。这是我的清单,至少是您需要的部分:
<activity android:name=".M4a1"
android:label="@string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="com.maxgenero.droidarmory.M4A1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter> …Run Code Online (Sandbox Code Playgroud)