I have found a mysterious problem that may be a bug! I have a list in my fragment. Each row has a button. List shouldn't respond to click however buttons are clickable.
In order to get which button has clicked I have created a listener and implement it in my fragment. This is the code of my adapter.
public class AddFriendsAdapter extends BaseAdapter {
public interface OnAddFriendsListener { public void OnAddUserClicked(MutualFriends user); }
private final String TAG = "*** AddFriendsAdapter ***";
When I run the app, I can see my rows however since my list is long and has over 200 items when i goto middle of list and click an item then returned position is wrong (it's something like 7, sometimes 4 and etc.).
Now what is the mystery? If I active on item listener of list from my fragment and click on row then correct row position will be displayed while on that row if I click on button then wrong position will be displayed.
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Log.e(TAG, "item " + position + " clicked."); } });
I am trying to find the user location with latitude and longitude. Is it possible to add a button to save the location (lat, long) and jump into another page? Or maybe get the image of the user location on the map. Do help me out on what to do. Thanks.
// Getting reference to the SupportMapFragment of activity_main.xml SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
// Getting GoogleMap object from the fragment googleMap = fm.getMap();
// Enabling MyLocation Layer of Google Map googleMap.setMyLocationEnabled(true);
// Getting LocationManager object from System Service LOCATION_SERVICE LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Creating a criteria object to retrieve provider Criteria criteria = new Criteria();
// Getting the name of the best provider String provider = locationManager.getBestProvider(criteria, true);
// Getting Current Location Location location = locationManager.getLastKnownLocation(provider);
LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // redraw the marker when get location update. drawMarker(location); }
@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
void saveLoc(){ if ( myLocation!=null){ // save Location in SharedPreference or a Database here SharedPreferences prefs = getSharedPreferences("myPreferences",Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putString("myLocation", myLocation); editor.commit(); // Start new activity Intent intent = new Intent(Map.this, SendMessage.class); startActivity(intent); } }
Logcat.txt
05-09 02:01:54.280: D/dalvikvm(508): GC_EXTERNAL_ALLOC freed 51K, 53% free 2576K/5379K, external 3129K/3266K, paused 72ms 05-09 02:01:57.891: W/KeyCharacterMap(508): No keyboard for id 0 05-09 02:01:57.891: W/KeyCharacterMap(508): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 05-09 02:02:34.450: W/KeyCharacterMap(508): No keyboard for id 0 05-09 02:02:34.450: W/KeyCharacterMap(508): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 05-09 02:02:34.490: D/dalvikvm(508): GC_CONCURRENT freed 1486K, 58% free 3019K/7111K, external 3430K/4246K, paused 6ms+4ms 05-09 02:02:46.381: I/dalvikvm(508): Total arena pages for JIT: 11 05-09 02:02:47.931: D/dalvikvm(508): GC_CONCURRENT freed 1315K, 59% free 2950K/7111K, external 3430K/4246K, paused 5ms+4ms 05-09 02:02:48.281: D/AndroidRuntime(508): Shutting down VM 05-09 02:02:48.281: W/dalvikvm(508): threadid=1: thread exiting with uncaught exception (group=0x40015560) 05-09 02:02:48.300: E/AndroidRuntime(508): FATAL EXCEPTION: main 05-09 02:02:48.300: E/AndroidRuntime(508): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{mp.memberuse/mp.memberuse.Map}: java.lang.NullPointerException 05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569) 05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 05-09 02:02:48.300: E/AndroidRuntime(508): at android.os.Handler.dispatchMessage(Handler.java:99) 05-09 02:02:48.300: E/AndroidRuntime(508): at android.os.Looper.loop(Looper.java:123) 05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.ActivityThread.main(ActivityThread.java:3683) 05-09 02:02:48.300: E/AndroidRuntime(508): at java.lang.reflect.Method.invokeNative(Native Method) 05-09 02:02:48.300: E/AndroidRuntime(508): at java.lang.reflect.Method.invoke(Method.java:507) 05-09 02:02:48.300: E/AndroidRuntime(508): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 05-09 02:02:48.300: E/AndroidRuntime(508): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 05-09 02:02:48.300: E/AndroidRuntime(508): at dalvik.system.NativeStart.main(Native Method) 05-09 02:02:48.300: E/AndroidRuntime(508): Caused by: java.lang.NullPointerException 05-09 02:02:48.300: E/AndroidRuntime(508): at mp.memberuse.Map.(Map.java:114) 05-09 02:02:48.300: E/AndroidRuntime(508): at java.lang.Class.newInstanceImpl(Native Method) 05-09 02:02:48.300: E/AndroidRuntime(508): at java.lang.Class.newInstance(Class.java:1409) 05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561) 05-09 02:02:48.300: E/AndroidRuntime(508): ... 11 more 05-09 02:02:55.531: I/Process(508): Sending signal. PID: 508 SIG: 9
Who can help me solve my problem. My LG E730 smartphone is have in someones of my friends without a sim card but with an internet connection over WiFi. How to calculate from where my smartphone connecting to internet, and how to find IP address of the phone? P.S. I can install any application on it over Google Play in my account using browser!
What app can help me to track where my smartphone is??
Hi, I have some questions. I would appreciate any assistance
Samsung Tab 2 (7.0, 3113 Wifi with IR)
Android vers 4.1.1 (afaik latest for this device)
1) Could anyone recommend a case? I need something that can flip (prefer a magnet based lock). It needs to be able to take massive impacts (ie. drop from onto cement from 2 meters) from EVERY angle, including corners. I also need it real quick (within 12 days) - so big department stores are good, and Amazon Prime is good (I live in Canada)
2) Is there any way to adjust screen dim time?
3) Is there any way to have the screen automatically turn on/off using the sensors? Namely, the light and proximity sensors. Ex. proximity sensor: IF object is detected within 2 cm continuously for 5 seconds, shut off screen. IF object is removed, turn screen on. I had a Nexus 7 with a magnetic flip case, in which the Nexus 7 would automatically turn on when the flap was opened, and turn off when the flap was closed, as sensed by its magnetometer.
4) Could I get detailed instructions into the installation of Cyanogenmod? What exactly is it good for? Any other BIOSes worth looking into?
5) A suggestion for a fast PDF reader? I need something that will process large, coloured images very quickly (a large sized travel book).
6) Any tweaks to maximize speed? I just bought it 2 days ago and its not as fast as I'd like even out of the box.
7) Is there any way to get better camera quality? I want to use it in the place of a discrete camera (personal reasons).
Thanks in advace. Any help with even one of the questions would be great.
I have row. 1) i have custom row in button and i want to when click button then open the alert box and this row clicked then open the new activity but Only one button clicked not row clicked . how to possible in this case. my code in below.
Thank you.
public class AlMessagesAdapter extends ArrayAdapter {
@Override public boolean onItemLongClick(AdapterView arg0, View arg1, int position, long arg3) { // TODO Auto-generated method stub
msg = userLIstArray.get(position).getMessage(); token = userLIstArray.get(position).getToken(); type = userLIstArray.get(position).getType(); int msgId = userLIstArray.get(position).getMessageid(); token = token.substring(0,token.length()-3); int token_value = Integer.parseInt(token) * 1000;
if(type.equals("text")) { Log.v("log", " if in text to Display " + msg + " token "+token); Intent i = new Intent(MessagesList.this,DisplayPopupActivity.class); i.putExtra("msg", msg); i.putExtra("token", token); i.putExtra("msgid", msgId); startActivity(i);
} else if(type.equals("photo")) { Log.v("log", " else in IMage to Display " + msg + " token "+token);
Log.v("log","token "+token+" type "+type + " position "+position + "msgId "+ msgId);
Intent i = new Intent(MessagesList.this,DisplayImageActivity.class); i.putExtra("imgData", msg); i.putExtra("token", token); i.putExtra("msgid", msgId); startActivity(i);
I have a class country with an arraylist that stores countries. I have created a get and set to add and get items from specified indexes from the array list but i wont work. Whenever i call an index from the arraylist i get an out of bounds exception because the array is empty or at least seems to be.
public class country extends Application {
public ArrayList countryList = new ArrayList(); public String Name; public String Code; public String ID;
public void setCountry(country c) { countryList.add(c); }
public country getCountry(int index) { country aCountry = countryList.get(index); return aCountry; }
to call the setter i use.
country ref = new country();
ref.setCountry(new country (sName, ID, Code));
then when i want to get an index
String name = ref.countryList.get(2).Name;
i have done the same thing but used a local arraylist and it populated fine and i was able to display the names so the datasource isnt the problem its whatever im doing wrong setting and getting the data inside the arraylist in the country class
I am trying to create a simple set of screens in an android app. The app begins with a menu screen with buttons. After a choice is made I then want to launch an activity built with 2 fragments (one for player 1 and another for player 2). However when I try and start the activity with the fragments I get an error in the android emulator.
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main_menu, menu); return true; }
// load up 1v1 duel activity public void beginRegularDuel(View view) { Intent intent = new Intent(this, OneVsOneDuelActivity.class);
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
After successfully using ProGuard on my application, it crashes on the startup on my mobile device. I use standard configuration of proguard: ${sdk.dir}/tools/proguard/proguard-android.txt
And logcat says something like this: E/AndroidRuntime(13441): at packagename.q.doInBackground(Unknown Source)
And then some App crashed errors etc.
Why does it not find my Source in doInBackground? Its a simple AsyncTask. Can anyone help me?
I'm trying to connect a socket with Android. I know that you can't open network-connections from MainThread. I have created an AsyncTask to do it. I have created and private class inside of the main class, I have seen some examples on internet about that.
Could someone help me about what it's wrong?? I guess that it's a error in the way I'm trying to connect because I have connected to the server with a normal Java class. I have edited the manisfest to give the necessary permissions.
If someone has any advise about a better way to do it, it would be great.
AsyncButtons asyncButtons = new AsyncButtons(); asyncButtons.execute(request);
}
@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_main, menu); return true; }
//Botones private class AsyncButtons extends AsyncTask { private Socket socket;
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
I have
String name = "admin";
then i do
String char = name.substring(0,1); //char="a"
I want to convert the char to it's ASCII value (97), how can i do this in java?
asked 12 mins ago
Instead of this:
String char = name.substring(0,1); //char="a"
You should use the charAt() method.
char c = name.charAt(0); // c='a' int ascii = (int)c;
answered 11 mins ago
Very simple. Just cast your char as an int.
char character = 'a'; int ascii = (int) character;
In your case, you need to get the specific Character from the String first and then cast it. Though cast is not required explicitly, but its improves readability.
int ascii = character; // Even this will do the trick.
answered 12 mins ago
Just cast the char to an int.
char character = 'a'; int number = (int) character;
The value of number will be 97.
answered 11 mins ago
It's simple, get the character you want, and convert it to int.
String name = "admin"; int ascii = name.charAt(0);
answered 7 mins ago
Convert the char to int.
String name = "admin"; int ascii = name.toCharArray()[0];
Also :
int ascii = name.charAt(0);
answered 9 mins ago
If you wanted to convert the entire string into concatenated ASCII values then you can use this -
String str = "abc"; // or anything else
StringBuilder sb = new StringBuilder(); for (char c : str.toCharArray()) sb.append((int)c);
BigInteger mInt = new BigInteger(sb.toString()); System.out.println(mInt);