Tag: java

Android: String format with Double value

I need to create a String using the Formater to display some double float values. I’m not clear on how to code it. Here is what I have: Double dWeightInKg = 100; Double dWeightInLbs = 220: String headerText = String.format(“%.0f kg / %.0f lbs”,Double.toString(dWeightInKg) , Double.toString(dWeightInLbs)); I’m looking for the following output: 100 kg / […]

Remove ListView footer Click Listener

ListView Footer RelativeLayout listFooterView = (RelativeLayout) inflater.inflate( R.layout.my_footer_layout, null); getListView().addFooterView(listFooterView); ListView OnClickListener listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) { // TODO Auto-generated method stub Intent i = new Intent(getApplicationContext(), Abc.class); startActivity(i); } }); On Click Listener works even if I click on footer View. How to disable […]

Android okHttp addFormDataPart dynamically for Multiple Image

Hello AndroidUploaders, I had given answer Uploading a large file in multipart using OkHttp but i am stuck with multiple image uploading. I want to upload dynamically 1 to 10 image at a time. RequestBody requestBody = new MultipartBuilder() .type(MultipartBuilder.FORM) .addFormDataPart(KEY_PHOTO_CAPTION, photoCaption) .addFormDataPart(KEY_FILE, “profile.png”, RequestBody.create(MEDIA_TYPE_PNG, sourceFile)) .build(); I have ArrayList of PhotoCaption class which has […]

Android GCM with product flavors

I have GCM sample android gradle project. Its worked well, when I add 2 flavors a push notification stopped to work. My compilation manifest (it’s taken from app\build\intermediates\manifests\ex\debug) file is below: <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.flavor.app” <uses-permission android:name=”com.flavor.app.permission.C2D_MESSAGE” /> <permission android:name=”com.flavor.app.permission.C2D_MESSAGE” android:protectionLevel=”signature” /> <receiver android:name=”com.google.android.gcm.GCMBroadcastReceiver” android:permission=”com.google.android.c2dm.permission.SEND” > <intent-filter> <action android:name=”com.google.android.c2dm.intent.RECEIVE” /> <action android:name=”com.google.android.c2dm.intent.REGISTRATION” /> <category android:name=”com.flavor.app” /> […]

Is there a limit for the number of files in a directory on an SD card?

I have a project written for Android devices. It generates a large number of files, each day. These are all text files and images. The app uses a database to reference these files. The app is supposed to clear up these files after a little use (perhaps after a few days), but this process may […]

Android Java : How to subtract two times?

I use some kind of stopwatch in my project and I have start time ex: 18:40:10 h stop time ex: 19:05:15 h I need a result from those two values like final time = stop – start I found some examples but they all are very confusing . Is there any simple solution ?

Setting user agent in Java httpclient and allow redirects to true

I am trying to set my user agent string in the HttpClient apache object in Java but I cannot find out how to do it. Please help! Also I am trying to enable redirects to true but also cannot find this option within the HttpClient object. Thanks Andy

Date format conversion Android

I have string form of date: 2011-03-27T09:39:01.607 and I want to format it to March 27, 2011 I am using DateFormat[] formats = new DateFormat[] { DateFormat.getDateInstance(), DateFormat.getDateTimeInstance(), DateFormat.getTimeInstance(), }; String actDate= formats[0].format(uploadeddate.substring(0,9)); but its not working. How do I convert to March 27, 2011?

Android BroadcastReceiver onReceive Update TextView in MainActivity

In MainActivity I have a TextView: textV1. I also have a method in MainActivity that updates that textview: public void updateTheTextView(final String t) { MainActivity.this.runOnUiThread(new Runnable() { public void run() { TextView textV1 = (TextView) findViewById(R.id.textV1); textV1.setText(t); } }); } In a BroadcasrReceiver I need to update the text in textV1 in MainActivity. public class […]

No such instance field

I’m trying to get my application to save some data when the orientation of the screen is changed using the onSaveInstanceState to save a boolean value mCheated. I’ve set numerous break points and am getting an error for the mCheated boolean value in the variables view mCheated= No such instance field: ‘mCheated’ I have no […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.