Posts

Showing posts with the label android

ListView/ExpandableListView randomly changes background colour on scroll/click/expand/collapse

Image
Working on the same android app which I posted about a couple of times earlier, I had this one feature I wanted to implement where I show a list of persons and highlight those from that list who have a birthday today. I tried a couple of different approaches to to the "highlight" the list items which had a birthday today for e.g: setting the background colour for those items, setting up a background icon for those, changing the text colour of the list item, and with all of these I faced 1 common problem: if I had to scroll the list or expand/collapse one item group (in case of ExpandableListView ), then it would end up highlighting some random items from the list, and if I continued that excercise, finally almost all items would get highlighted. Since I had used an ExpandableListView , my getGroupView method looked somewhat like this: @Override  public View getGroupView(int groupPosition, ..., ViewGroup parent) {   Person person = (Person) getGroup(groupPosition);  ...

PreferenceFragment shows up with a transparent background

Image
In an android app that I'm currently working on, I wanted use Android's Preference API to provide an interface to modify some app specific settings. I didn't want to create another Activity or PreferenceActivity for that, and hence I thought of simply using a PreferenceFragment . Now, in my project I already had a MainActivity ( extends ActionBarActivity ) which had a MainFragment wired up to it somewhat like this in it's onCreate method: getSupportFragmentManager().beginTransaction()  .add(R.id.container, new MainFragment())  .commit(); And because of that I knew that I had to replace the existing MainFragment with my new SettingsFragment which extended PreferenceFragment . With that in mind, I went ahead and added the following to my MainActivity 's onOptionsItemSelected : getFragmentManager().beginTransaction()  .replace(R.id.container, new SettingsFragment())  .addToBackStack(null)  .commit(); When I saw this work in the emulator, it looked some...

"Application not installed" when APK is not signed

I wanted to test a small android app which I was working on, on my phone. I had already tested this app on an emulator and even on a physical device - my phone earlier, but I had done that via ADB. However, I wanted to install it this time from the apk file. Now, when I ran gradlew assembleRelease there were 2 apk files generated in the projectname /build/apk directory. One named projectname -debug-unaligned.apk and the other named projectname -release-unsigned.apk . The release unsigned one seemed to be the right one to try out. So I tried installing it on my phone. Everything went on well until I saw a message when it had just seemed like the app was installed which actually read: "Application not installed". I was a bit confused looking at the message, I didn't quite understand what went wrong as there was no details as to what went wrong in the message. I had pretty much everything configured the way I thought would be required like checking off the box against ...

Bundle containsKey() but returns null on getString()

Back to blogging after a long time, and this time its quite a lame one which I usually wouldn't want to blog about, but I did spend close to an hour trying to figure out what I was doing wrong. I just started a small android application and was trying to send a paramter from one Activity to another. Now, after a bit of searching around, I found out that I needed to create an Intent Bundle and put the parameter in it, and the new Activity which gets started will be able to fetch it from the same Bundle using the key that was provided while inserting data into the Bundle . So, I had something like this in the first activity: Intent intent = new Intent(FirstActivity.this, SecondActivity.class); EditText nameText = (EditText) findViewById(R.id.query_textbox); intent.putExtra("queryKey", nameText.getText()); startActivity(intent); and something like this in the second activity: Bundle extras = getIntent().getExtras(); String query = extras.getString("queryKey");...