How to obtain the text color of a single item within an Android ListView
-
21-12-2019 - |
Question
My ListView contains items that are different text colors. I need to grab the color state of each item to to be saved within the onSaveInstanceState of my fragment.
ListView lvItems = (ListView) getActivity().findViewById(R.id.lvItems);
lvItemsArray.add("Testing1234");
lvItemsAdapter = new ListViewAdapter(getActivity(), lvItemsArray);
lvItems.setAdapter(lvItemsAdapter);
Solution 2
Found it from another user on here, thanks.
View view = ListAdapter.getView(0, null, null);
TextView textView = (TextView) view.findViewById(R.id.myitemRow);
ColorStateList mlist = textView.getTextColors();
int color = mlist.getDefaultColor();
OTHER TIPS
LitView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Log.d("TextView",""+arg1.TextView.getTextcolor());
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow