Best practices combining list and non-list views, like the Market

I'm trying to tackle a problem that seemingly many Android developers have, which is how to intersperse lists with non-list data, in one big scrollable pane.

The model I have in mind is the screen for an individual app in the Market. You have a big description, a list of a few lazily loaded comments, and then some individual items that do different things, like visit the developer's web page, call them, etc. And then in between them all, are nice section headers.

Emulating this approach seems to be extremely hard. I've read enough SO answers and mailing list posts to know not to put a ListView inside of a ScrollView, but I want the same effect without using addHeader() and addFooter() with very complex header and footer views.

I've tried using a LinearLayout that I stock with views myself, but I can't get the pleasant click effects that default list items have (the orange background, white for long-click, etc.).

What do I do?


Asked by: Lily473 | Posted: 24-01-2022






Answer 1

Take a look at my MergeAdapter, which is designed to handle scenarios like this.

Answered by: Miranda194 | Posted: 25-02-2022



Answer 2

Why not use a header? It's easy. Define the header contents in a separate layout. Your activity layout contains nothing but the ListView that you want at the bottom. No scroll view!

Then call

View headerView = getLayoutInflater().inflate(R.layout.header_layout, null);
ListView listView = (ListView) findViewById(R.id.my_list_view);
listView.addHeaderView(headerView, null, false);   

It's crucial to call that form of addHeaderView so that the header is disabled. Otherwise, it can be selected, which looks totally weird.

Answered by: Tara799 | Posted: 25-02-2022



Answer 3

Mark's example would work. basically you need an adapter with different view types. Another nice example is http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/ which might work better than Mark's because you want to have separators and group things together.

Answered by: Oliver536 | Posted: 25-02-2022



Similar questions

google play - Options and best practices to release free and paid version of the same app to Android Market

I have installed a couple of free apps on my Android phone and then later "upgraded" to the paid full version. My first instincts for doing the same would be to create two apps with the same package name so that installing one overwrites the other, but apps in the Market must be unique by package name. What are some patterns and best practices for sharing code and resources for free and paid versions of the same a...


Sharing elements between Android apps, a question of best practices

Here's a quote from Android's Dev Guide: A central feature of Android is that one application can make use of elements of other applications (provided those applications permit it). For example, if your application needs to display a scrolling list of images and another application has developed a suitable scroller and made it available to others, you can call upon that scroller to ...


Android App with multiple views - Best Practices?

I am new to developing for android. I have a question regarding some best practices. My app is like a dashboard from which multiple different "sub-activities" can be started and done. I am wondering what is the best way to structure the app. One way is to have different layouts and load and unload them appropriately. The other is to start new activities using intents. At least this is what i have gathered from wha...


Best practices for split testing Android apps

For web applications split testing various options get usually split tested to maximize their effectiveness with tools like Google Website Optimizer. One of the most impressive example might be Google and how the split tested dozens of shades of blue to find the right one. When developing android applications are there best practices to follow for A/B testing or multivariate testing?


sqlite - Best practices for exposing multiple tables using content providers in Android

I'm building an app where I have a table for events and a table for venues. I want to be able to grant other applications access to this data. I have a few questions related to best practices for this kind of problem. How should I structure the database classes? I currently have classes for EventsDbAdapter and VenuesDbAdapter, which provide the logic for querying each table, while having a...


android - Store object into SQLite database best practices

I would like to store an object into a SQLlite database. I am looking for how to best do it in order to ensure that if I need to updata/change this object in the future that users of the new and old object layout will be minimally impacted. In other words I want to ensure that making changes to the object will have minimum affect on clients that do not update their software on the old database format. I want to also ensure...


mobile - Android Multiple Devices Best Practices

I have several android applications in the market. Some users are reporting force closes on certain devices. The only device I test on/have access to is a Nexus One. I also test my applications on many different permutations of the simulator. Does anyone have any advice on how to ensure device compatibility? Or anything in general to avoid issues like this? Currently I am getting complaints from Samsung Moment and ...


testing - android ndk practices

Now with the release of new android NDK, given the fragmentation of android devices, what testing measures one should employ to test over different phones, tablets and/or google tv based devices?


security - Best Practices on Storing Login Info on Android

I'm kinda of a noob at Android and I'm writing a simple app, for my own personal learning, to hookup to an external API (Flickr or Netflix). What I want to do is ask the user for their login info to either site so that they can view their pictures or dvd queue. My question is what's the best practice to store user data like that? I was thinking of encrypting the login/pwd and store it onto the SD card. Any tho...


android - best practices for handling UI events

I have put the all the binding code for UI events on OnCreate(). It has made my OnCreate() huge. Is there pattern around implementing UI events in android ? Can I add methods in View xml file and then I can put all the handler code somewhere else. In a nutshell , I think I am asking how can I implement MVVM pattern with android app code ?






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top