动态更新TextView

时间:2013-03-01 23:59:51

标签: android

我想实时更新listview中的TextView。我有一个套接字连接,我正在监听json消息,我想解析/识别json以更新现有列表中的5个TextView之一。

responseid=object.getString("ResponseID");
    if(responseid!=null){
        for(int j=0;j<myList.size();j++){
            //If value match then I want to update the textView of that particular row
            if(myList.get(j).getName().equals(cid)) { 
                   //I successfully get the value of Textview of particular row of Listview now I want to update the this Textview with item variable below.
                String item = (String) myAdapter.getItem(j).getName();
                //Here i want to update Textview
                myAdapter.notifyDataSetChanged();
            }
        }    
    }

2 个答案:

答案 0 :(得分:1)

responseid=object.getString("ResponseID");
    if(responseid!=null){
        for(int j=0;j<myList.size();j++){
            if(myList.get(j).getName().equals(cid)) { 
                String item = (String) myAdapter.getItem(j).getName();
                ((TextView)myList.get(j)).setText(item);
                myAdapter.notifyDataSetChanged();
            }
        }    
    }

答案 1 :(得分:0)

通过调用String item = (String) myAdapter.getItem(j).getName();,您只需获取商品名称值。

要将getItem的值设置为已定义的类:

YourObjectType item = (YourObjectType)myAdapter.getItem(j);
item.setName("updatestring");
myAdapter.notifyDataSetChanged();