manipulate string to substring on java - substring

after long googling days, no success.
i just want to get the first number from "result=0.23 562"
here is my code, i will appreciate any help!
by the way this is an android app
the function ServerTransfer() just getting data from phone's USB.
package com.WiMiapplication.wimi;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class trackingActivity extends Activity{
TextView Fields;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.trackingsub);
}
#Override
protected void onResume() {
super.onResume();
new ServerTransfer(){
int indexend=0;
int indexstart=0;
private String Dude ="3";
#Override
public void onPostExecute(String result){
for(int i=0;i<=result.length();i++){
String Spectate=Character.toString(result.charAt(i));
if(!Spectate.equals(" ")){
indexend++;
} else{
Dude =result.substring(result.indexOf(" ") + 3);
}
}
Fields = (TextView)findViewById(R.id.X_location);
Fields.setText(result);
}
}.execute();
}
}

try this:
Dude =result.split(" ")[0];

Related

how can i communicate with webview, i want to search character using textWatcher

i want to highLight sometext which is searched. (from editText)
example : when i enter character ; 'yahoo' will be highLighted.
is this hard thing? im literally noob. but i wnat to do this.
i found method 'textWatcher'. he can just bring me character(when it's changed each time)
or do i use searchView?
please check my code. MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.webkit.WebView;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText editText;
WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText)findViewById(R.id.editText);
editText.addTextChangedListener(watch); // == (this), implements TextWatcher
webView = (WebView)findViewById(R.id.webView);
webView.loadUrl("https://www.yahoo.com/");
}
TextWatcher watch = new TextWatcher(){
#Override
public void afterTextChanged(Editable arg0) { }
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { }
#Override
public void onTextChanged(CharSequence s, int a, int b, int c) {
Log.d("onTextChanged","CharSequence s #"+s);
}
};
}
also, i input permission-code in manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
how do i fix this? please give me your tips.

Eclipse error com.avaje.ebean.EbeanServer not resolved

In Eclipse I have an error on my top blank line and I cant get rid of it. Here's my code (I am making a bukkit plugin):
//this is where I get the error
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
#Override
public void onEnable() {
new EventHandler(this);
}
#Override
public void onDisable() {
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("BLANK") && sender instanceof Player) {
Player player = (Player) sender;
return true;
}
return false;
}
}
I can't find anyway around it. Please help.
You appear to be missing your package name. Try this instead:
package my.package.name;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
#Override
public void onEnable() {
new EventHandler(this);
}
#Override
public void onDisable() {
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("BLANK") && sender instanceof Player) {
Player player = (Player) sender;
return true;
}
return false;
}
}
Remember to replace my.package.name with your package name.

How to call a class from another activity?

I want to call MainActivity class to another activity. This is my code for the MainActivity.java:
package com.blinkedup.geolocationchat;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.app.Service;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
TextView textView;
LocationManager locationManager;
MyLocationListener locationListener = new MyLocationListener();
Criteria criteria;
String bestProvider;
String listOfBestProviders;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
criteria = new Criteria();
textView = (TextView) findViewById(R.id.textView1);
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
locationManager = (LocationManager) getSystemService(Service.LOCATION_SERVICE);
//locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
bestProvider = locationManager.getBestProvider(criteria, true);
Toast.makeText(getApplicationContext(), bestProvider, 3).show();
}
protected void onPause(){
super.onPause();
locationManager.removeUpdates(locationListener);
}
private class MyLocationListener implements LocationListener{
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
textView.setText("Latitude: " + location.getLatitude() +
"Longitude: " + location.getLongitude());
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}
In another activity I wanted to call the lat and long of the above code but don't want to rewrite the code to the activity. I just want to call it and display the result in another activity. please help. thanks
make your variable static and define it before onCreate() method use that variable in another activity by call like this.
YourMainActivity.yourstaticvariable

How To Get Tab Text in GWT?

how do I get the text of a selected tab in GWT? I see there is a method com.google.gwt.user.client.ui.TabBar.setTabText(String text) but how do I get the text?
I ended up extending TabPanel like so:
package com.benhowden.gwttemplate;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.Widget;
import java.util.ArrayList;
import java.util.List;
public class DFSTabPanel extends TabPanel {
List<String> tabsTexts;
public DFSTabPanel() {
super();
tabsTexts = new ArrayList<String>();
}
#Override
public void add(Widget w, String tabText) {
super.add(w, tabText);
tabsTexts.add(tabText);
}
#Override
public boolean remove(int index) {
boolean removed = super.remove(index);
if(removed) {
tabsTexts.remove(index);
return removed;
}
return removed;
}
#Override
public void clear() {
super.clear();
tabsTexts.clear();
}
public String getTabText(int index) {
return tabsTexts.get(index);
}
}

GWT: gwt-exporter: passing objects

I've been struggling with passing Java objects from Java through JSNI (gwt-exporter generated) into Java and wonder if anybody can help?
I am creating an object in Java ("Person"), passing it to a JSNI method ("displayPerson") that invokes a Java method exposed with gwt-exporter ("CommonService.displayPerson"); however the parameter to the last stage becomes null.
If I pass a String it works OK; it's just with my objects I hit the problem.
Person is defined in a GWT application JAR inherited by the other GWT application.
Thanks for looking,
Mike
GWT application
package com.anstis.pluginserver.client;
import com.anstis.plugincommon.shared.Person;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
public class PluginServer implements EntryPoint {
public void onModuleLoad() {
GWT.create(CommonService.class);
onLoadImpl();
RootPanel.get("container").add(getButton());
}
private native void onLoadImpl() /*-{
if ($wnd.jscOnLoad && typeof $wnd.jscOnLoad == 'function') $wnd.jscOnLoad();
}-*/;
private Button getButton() {
Button btn = new Button("Click!");
btn.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Person p = new Person();
p.setName("Smurf");
p.setAge(500);
displayPerson(p);
}
});
return btn;
}
private native void displayPerson(Person person) /*-{
// The below displays shows 'person' is not null
alert("PluginServer.displayPerson.person is " + (person != null ? "not " : "") + "null");
try {
var pluginServer = new $wnd.com.anstis.pluginserver.CommonService();
// The below displays shows 'pluginServer' is not null
alert("PluginServer.displayPerson.pluginServer = " + pluginServer);
pluginServer.displayPerson(person);
} catch(err) {
alert(err);
}
}-*/;
}
CommonService.java
package com.anstis.pluginserver.client;
import org.timepedia.exporter.client.Export;
import org.timepedia.exporter.client.Exportable;
import com.anstis.plugincommon.shared.Person;
import com.anstis.plugincommon.shared.PluginCallback;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
#Export
public class CommonService implements Exportable {
public void displayPerson(Person person) {
//The below shows 'person' *IS* null
Window.alert("CommonService.displayPerson.person is "
+ (person != null ? "not " : "") + "null");
Window.alert("Name=" + person.getName());
}
}
Person.java
package com.anstis.plugincommon.shared;
import org.timepedia.exporter.client.Exportable;
public class Person implements Exportable {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
You need no to implement Exportable for Person class.
public class Person {
and it works.
If anybody else stumbles across this question, I now have a working example at git://github.com/manstis/gwt-plugins.git