我有活動A與listView和活動B與窗體。我接觸到來自活動A的項目並從活動B中調用表單。在填寫完表格並完成活動後,我觸摸一個項目「Laura」並打開一個關於她的表格。我返回字符串「Laura」,並且想要更改Laura的Item ListView顏色。我怎樣才能做到這一點?如何使用onActivityResult更改Item ListView顏色?
-1
A
回答
1
您應該使用一個布爾檢查,如果你使勞拉帳戶的一些改變,所以它會是這個樣子:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == REQUEST_ACCOUNT_LAURA) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// The user changed Laura account.
boolean isAccountChanged= data.getBooleanExtra("isAccountChanged", false);
if (isAccountChanged) {
ListView listView = new ListView(this);
// Get the view associated with Laura, and change the background color.
((View) listView.getItemAtPosition(position)).setBackgroundColor(R.color.black);
listView.getAdapter().notifyDataSetChanged();
}
// Do something with the contact here (bigger example below)
}
}
}
您也可以使用這onListItemCLick,你可以在你的ListView設置:
View lastTouchedView;
@Override
public void onListItemClick(ListView parent, View v, int position, long id)
lastTouchedView.setBackgroundColor(Color.WHITE);
v.setBackgroundColor(Color.CYAN);
lastTouchedView = v;
}
+0
感謝名單,但我不能在onActivityResult中不改變listView顏色,你試試看簡單的listView.setBackgroundColor(R.color.black),你不會得到它! – daniel12345smith
+0
您需要重置列表視圖適配器。可以使用 adapter.notifyDataSetChanged()或者只使用listView.setAdapter(new Adapter()...) – risto
0
除了「Laura」之外還會返回其他內容。也許返回一個包中的對象? OnActivityResult()不僅限於基元類型。實驗與,看看你能做到什麼=)
相關問題
- 1. 如何設置WPF ListView Selected Item顏色?
- 2. Bug - ListView - > item - > button OnClick:更改父項的背景顏色
- 3. 如何更改jQuery Mobile Listview的顏色
- 4. 如何更改ListView字體顏色?
- 5. 如何更改ListView的字體顏色
- 6. 如何更改ListView項目的顏色
- 7. 在ListView中更改顏色
- 8. 在ListView中更改顏色
- 9. 如何更改ListView的顏色,交替排列顏色?
- 10. Jquery Mobile ListView Seleted Item CSS顏色
- 11. 如何更改ons-list-item中的on-select顏色
- 12. 禁用/更改ListView中HoverOver的顏色
- 13. 如何使用Swift更改MKAnnotation顏色?
- 14. 如何使用.NET ColorMatrix更改顏色?
- 15. 如何使用onmouseover更改顏色?
- 16. 更改ListView中的文本顏色
- 17. 更改ListView陰影顏色和大小
- 18. 將顏色更改爲Listview列項目
- 19. 更改所選ListView項目的顏色
- 20. 更改ListView的背景選擇顏色?
- 21. 更改ListView項目的文本顏色
- 22. 更改ListView項項的文字顏色
- 23. 更改ListView的字體顏色
- 24. 更改背景顏色的ListView
- 25. 更改kivy的文本顏色ListView ListItemButton
- 26. ListView更改2.x的顏色
- 27. 更改文本的顏色在ListView
- 28. onTouch on ListView,更改項目的顏色
- 29. 更改ListView的文本顏色
- 30. 更改VB6中ListView的背景顏色
嘗試檢查這個StackOverflow的鏈接出:對於答案http://stackoverflow.com/questions/5564789/change-listviews-textcolor – jcameron47