I can not decide for himself the task will be to ask
I want to measure the height of the ListView. Can not catch the moment of rendering ListView (rssListView.getHight(); = 0 )
public class RSSactivity extends Activity {
public static RssItem selectedRssItem = null;
String feedUrl = "";
ListView rssListView = null;
ArrayList<RssItem> rssItems = new ArrayList<RssItem>();
ArrayAdapter<RssItem> aa = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
rssListView = (ListView) findViewById(R.id.rssListView);
aa = new ArrayAdapter<RssItem>(this, R.layout.list_item, rssItems);
rssListView.setAdapter(aa);
feedUrl = rssURLTV.getText().toString();
refressRssList();
rssListView.getWidth(); // = 0 ,
}
private void refressRssList() {
ArrayList<RssItem> newItems = RssItem.getRssItems(feedUrl);
rssItems.clear();
rssItems.addAll(newItems);
aa.notifyDataSetChanged();
}
}
target to calculate the number of items intermeddle ListView screen
In onCreate:
rssListView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// If you need this to be called again, then run again addOnGlobalLayoutListener.
mainPanel.getViewTreeObserver().removeGlobalOnLayoutListener(this);
rssListView.getWidth(); // It's available here.
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With