我有一个带输入字符串的程序.我想删除字符'<'和'>'中的任何内容.例如,如果字符串说
"P.S.<!--
BODY
{
color:white;
background-color: transparent;
font-family:sans-serif;
}
--> Hello how are you today?"
Run Code Online (Sandbox Code Playgroud)
我希望输出字符串只包含"P.S. Hello how are you today?"
.在Java中有一种简单的方法吗?谢谢
我试图有一个恒定的gps监听器,每隔x分钟将其位置(长和lat坐标)发送到Web服务器.在按钮上单击它还会将其位置发送到Web服务器.我知道要获取gps信号,你可以输入寻找位置的频率,但是如何编写一个程序可以获得gps位置并每x分钟发送一次坐标(即使在背景中也没有按下按钮) ?
//在点击中
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, whatshouldIputhere?, 0, this);
Run Code Online (Sandbox Code Playgroud)
和
public void onLocationChanged(Location location) {
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
}
}
Run Code Online (Sandbox Code Playgroud) 我用的String
是:
String message = "%%NAME is inviting you";
Run Code Online (Sandbox Code Playgroud)
我在message.replaceAll("%%NAME", me);
哪里me
使用String
.这行代码对我不起作用.我想知道我做错了什么?
我正在编写一个应用程序,每十分钟就会记录一个新的gps位置.
我已经尝试了位置轮询器,将位置监听器放在服务中,并将位置监听器放在一个活动中,但这些方法都不适用于我.
我需要一种方法在我开始记录我的位置数据前2分钟打开gps位置监听器(为gps提供足够的时间来查找位置或确定没有信号).我一直在使用在我调用updatelocation类之前2分钟调用gpsActivity的警报.然后我的updatelocation类接受gpsActivity的locationmanager并从中提取一个位置.
从理论上说这应该可以工作但是当我把它放在我的手机上时,我总是得到不好的数据(准确度太低或根本没有信号)
如果有人可以帮助我,我将非常感激.
谢谢
报警在更新位置前2分钟呼叫此课程
public class GPSActivity extends Activity {
public static LocationListener loc_listener = null;
public static LocationManager locationManager = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
getGPS();
}
public static void getGPS() {
if (loc_listener == null) {
loc_listener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onProviderDisabled(String provider) {}
@Override
public void onLocationChanged(Location location) …
Run Code Online (Sandbox Code Playgroud) 我想在单击按钮以获得搜索栏后弹出一个警告对话框,以便此人可以更改1-48中的值.我已经制作了一个自定义xml,它有一个搜索栏和两个文本视图,我希望对话框有两个按钮,一个只是取消对话框,另一个做更多工作.这是我到目前为止的代码.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SeekBar android:max="48" android:layout_height="wrap_content" android:id="@+id/seekBar1" android:layout_width="fill_parent" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_marginTop="74dp"></SeekBar>
<TextView android:text="Change Hour Range" android:layout_height="wrap_content" android:id="@+id/textView1" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"></TextView>
<TextView android:text="Only most recent positions" android:layout_height="wrap_content" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:layout_marginTop="15dp"></TextView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的警报对话框
new AlertDialog.Builder(ImTracking.this)
//is there something like setcontentview for alert dialogs?
.setPositiveButton("Cancel", null)
.setNegativeButton("OK",
new DialogInterface.OnClickListener() {
// does some work here
Run Code Online (Sandbox Code Playgroud) 我正在尝试Intent服务.这就是我用它来称呼它
Button updateLocation = (Button) findViewById(R.id.btnUpdateLocation);
updateLocation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent updateLocIntent=new Intent(ImTracking.this,UpdateLocation.class);
startService(updateLocIntent);}});
Run Code Online (Sandbox Code Playgroud)
但是在我的UpdateLocation类中,它永远不会碰到我的任何断点.
public class UpdateLocation extends IntentService{
public UpdateLocation() {
super("UpdateLocation");
}
@Override
protected void onHandleIntent(Intent intent) {
SharedPreferences prefs = getSharedPreferences("Settings", 0);
final String id = prefs.getString("ID", "");
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(
"http://iphone-radar.com/gps/gps_locations");
JSONObject holder = new JSONObject();
...
Run Code Online (Sandbox Code Playgroud)
到底是怎么回事?
谢谢
PS.我正在使用它,因为我想用一个报警管理器来调用它.但是,在按钮单击时,我想显示一个进度对话框,我将在哪里放置意向服务的进度对话框?(到目前为止,我只有使用异步任务的经验)
据我了解, fl_image 接受一个管道函数,该函数应该只接受单个图像,即processedClip = input_file.fl_image(imagePipeline)
在哪里
def imagePipeline(img):
....
返回最终图像
但是如果我们的 imagePipeline 函数接受更多参数怎么办
IE
def imagePipeline(img, arg1, arg2, arg3):
...
返回最终图像
我们如何向 fl_image 中的 imagePipeline 添加参数?
我试图将一个int数组保存到共享首选项中.
int myInts[]={1,2,3,4};
SharedPreferences prefs = getSharedPreferences(
"Settings", 0);
SharedPreferences.Editor editor = prefs
.edit();
editor.putInt("savedints", myInts);
Run Code Online (Sandbox Code Playgroud)
由于putInt方法不接受int数组,我想知道是否有人知道另一种方法.谢谢
我想在一秒计时器上更改我的应用程序的背景图像(更改两个图像之间的背景).我知道如何在按下按钮时更改图像,但是我很难找到定时器的代码.我该怎么办?
谢谢.
我从网站获取数据并放置在文本视图中,以便我可以使用setGravity(Gravity.CENTER)将其居中.但是,当我将文本视图放在警告对话框中时,我无法再向下滚动以查看消息的结尾.有人可以帮我解决这个问题吗?谢谢
TextView msg1=new TextView(Welcome.this);
//Takes data from a website
msg1.setText(Html.fromHtml(getText("http://www.cellphonesolutions.net/welcome-en")));
msg1.setGravity(Gravity.CENTER);
LinearLayout dialogLayout = new LinearLayout(Welcome.this);
dialogLayout.addView(msg1);
dialogLayout.setOrientation(LinearLayout.VERTICAL);
AlertDialog welcome = new AlertDialog.Builder(Welcome.this).create();
welcome.setView(dialogLayout);
welcome.setButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//rest of the code....
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建这样的数组["stringone","stringtwo"]
并将其传递给Web服务器.当我试图做一个字符串数组使其像String[]={"stringone","stringtwo"]
它很奇怪通过{"userids":"[Ljava.lang.String;@406fe4b8"}
我应如何构建我的JSON数组,如果不使用字符串数组?
谢谢
我有一个警告对话框,应该将布尔值设置为true.因为setPositiveButton
我将Dialog onclick
接口设为null.当我添加onClickListener
到setNegativeButtons
onclick
接口它给了我一个编译错误说法:该方法setNegativeButton(int, DialogInterface.OnClickListener)
的类型AlertDialog.Builder
是不适用的参数(String, new View.OnClickListener(){})
这是我的代码,为什么我得到编译错误,我该如何解决这个问题?谢谢
new AlertDialog.Builder(ImTracking.this)
.setMessage(
Html.fromHtml(getText("http://www.cellphonesolutions.net/im-following-"
+ getResources().getString(
R.string.Country))))
.setPositiveButton("OK", null)
// The red squigly is under the .setNegativeButton
.setNegativeButton("Don't Remind", new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
SharedPreferences prefs= getSharedPreferences("Settings",0);
SharedPreferences.Editor editor=prefs.edit();
editor.putBoolean("ImTrackingDontRemind",true);
editor.commit();
}
}).show();
Run Code Online (Sandbox Code Playgroud)