开发者

Problems with onItemClick()

 public void onCreate(Bundle开发者_如何学C savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listascombarra);
    listView = (ListView)findViewById(android.R.id.list);
    listView.setTextFilterEnabled(true);

    listView.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            COUNTRIES[it]="TESTES";
            it++;
        }
    });
}

protected void onStart() {
    super.onStart();
    adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, COUNTRIES);
    listView.setAdapter(adapter);
}

So I have problems with the event, because when I click on an ItemList the string COUNTRIES don't modify, but if I scroll down it is modified sometimes. Is weird, some help?

Look at the pastebin url:

http://pastebin.com/DsYP2RkX


You are changing the string array that is part of the adapter, but you need to notify the list view (which is built using the adapter) that the string array has changed.

You can do this via the:

notifyDataSetChanged

function of the ArrayAdapter class. So in your on click function, call notifyDataSetChanged and see if that helps.


You marked the String[] as "Final" that means it can never change. Remove the "final"


I think you may want to use onListItemClick instead of onItemClick

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜