Setting height of ListView dynamically in run-time

by patrick » Wed, 21 May 2008 14:11:19 GMT


Sponsored Links
 hi

I want to set the height of a ListView during run-time of my
application. It seems that setPreferredHeight(int) doesn't do this job
and I can't find any similar function.

Did somebody already do something similar?

Thanks,
Patrick
--~--~---------~--~----~------------~-------~--~----~



Setting height of ListView dynamically in run-time

by Mark Murphy » Wed, 21 May 2008 14:32:01 GMT


 


I haven't tried this, but here are two ideas:

1. It's possible you need to call requestLayout() on the ListView (or 
possibly the ListView's parent) after calling setPreferredHeight() to 
affect the change.

2. It's also possible that you really need to adjust the height field of 
the LayoutParams for your ListView (obtained through getLayoutParams()), 
then call requestLayout(). Check out the Layout section of the View 
class documentation to see what I mean:

 http://code.google.com/android/reference/android/view/View.html 

If either of those work, let us know!

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
The Busy Coder's Guide to Android Development -- coming in June 2008!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Setting height of ListView dynamically in run-time

by patrick » Wed, 21 May 2008 14:56:03 GMT


 Hi Mark,




this is the one that works! Here a small code snippet:

AbsoluteLayout al = (AbsoluteLayout)
findViewById(R.id.attachment_layout);
ViewGroup.LayoutParams params = al.getLayoutParams();
params.height = 400;
al.requestLayout();

where the height is specified in "px"

Thanks!
Patrick
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. why is there no android tablet nearly as good as ipad?

There are a few good Android tablets around (Dell Streak, Huawei S7, Cisco 
Cius).

It took apple 3 years to come up with the iPad after the iPhone, we're still 
only 18 months in to Android :).

Al.
--

* Looking for Android Apps? - Try http://andappstore.com/ *

======
Funky Android Limited is registered in England & Wales with the company number  
6741909. 

The views expressed in this email are those of the author and not necessarily 
those of Funky Android Limited, it's associates, or it's subsidiaries.







-- 

2. Don't see YouTube thumbnails anymore on Froyo

Hi.

using a WebView with Froyo I don't see the YouTube thumbnails anymore.
WebViewClient.shouldOverrideUrlLoading() is not called in Froyo, but was
called before. Please check out the example below. With Pre-Froyo you would
see a YouTube thumbnail two/thirds into the article, with Froyo you don't.

Any ideas?

Cheers,
Mariano

public class WebViewTestActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                WebView wv = (WebView) findViewById(R.id.webview);
                wv.setWebViewClient(new WebViewClient() {
                        public boolean shouldOverrideUrlLoading(WebView view, 
String url) {

                                if (url.startsWith("http:") || 
url.startsWith("https:"))
                                        return false;

                                Intent intent;

                                try {
                                        intent = Intent.parseUri(url, 
Intent.URI_INTENT_SCHEME);
                                } catch (URISyntaxException ex) {
                                        Log.w("Browser", "Bad URI " + url + ": 
" + ex.getMessage());
                                        return false;
                                }

                                if (getPackageManager().resolveActivity(intent, 
0) == null) {
                                        String packagename = 
intent.getPackage();
                                        if (packagename != null) {
                                                intent = new 
Intent(Intent.ACTION_VIEW,
                                                                
Uri.parse("market://search?q=pname:"
                                                                                
+ packagename));
                                                
intent.addCategory(Intent.CATEGORY_BROWSABLE);
                                                startActivity(intent);
                                                return true;
                                        } else {
                                                return false;
                                        }
                                }

                                intent.addCategory(Intent.CATEGORY_BROWSABLE);
                                intent.setComponent(null);
                                try {
                                        if (startActivityIfNeeded(intent, -1)) {
                                                return true;
                                        }
                                } catch (ActivityNotFoundException ex) {
                                }

                                return super.shouldOverrideUrlLoading(view, 
url);
                        }

                });

                wv.getSettings().setPluginsEnabled(true);
                wv
                                
.loadUrl("http://www.fscklog.com/2010/06/sammelsurium-zweite-ipad-
auslieferungswelle-scheint-anzulaufen-iphone-codesperre-kann-auch-unter-windows-
ausgetrickst-werde.html");
        }
}

-- 

3. Service getting Killed

4. Issue in downloading Android Source

5. Filter email Exchange di Android

6. Best httpclient re-use stategy

7. Penampakan HP Cina Dual Booting Android/WM 6.5 T535