如何在列表视图更新添加按钮? [英] how to add button when listview is updated?

查看:219
本文介绍了如何在列表视图更新添加按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里输入的形象描述

我工作的应用而得到GCM数据,在此之后我ListView中显示的数据,并在从GCM获得新的数据,我这些新数据添加到ListView和我用这个code

I'm working on App which get the data from GCM , After this I display the data in the listview and when get new data from GCM , I add these new data to the listview and I used this code

public void updateListView2(List<FeedItem> newItems) {
    for(FeedItem item : newItems)
    {
        //Toast.makeText(this, "Title : "+item.getTitle(), Toast.LENGTH_LONG).show();

        // this to add the new items at the top of the list
        listAdapter.insert(item, 0);
    }
    // to retain the position of the listview after updated
    int lastViewIndex = listView.getFirstVisiblePosition();
    View view = listView.getChildAt(0);
    int top = (view == null) ? 0 : view.getTop() ;
    listView.setSelectionFromTop(lastViewIndex, top);
    listAdapter.notifyDataSetChanged();
       //this to add the button programitcally like "New Stories"
    Button updateBt = new Button(this);
    updateBt.setText("Updated");
    feedLayout.addView(updateBt);
}

但是当我试图添加按钮,这样的故事新编我失败了,没有什么是观察!所以任何人都可以帮助我。

but when I tried to add the button like this "New Stories" I failed , Nothing is viewed !! so can anyone Help Me .

推荐答案

做的最好的方法是添加按钮,并把它无论你想在你的XML布局文件,并设置

The best way to do is add that button and place it wherever you want in your xml layout file and set

android:visibility="gone"

android:visibility="invisible"

在您需要的按钮显示,从Java code这样的显示它

when you need the button to display, display it from java code like this

myButton.setVisibility(View.VISIBLE);

按照这个,你会得到没有问题。

follow this, you'll get no issues.

这篇关于如何在列表视图更新添加按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆