Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Attached are 2 photos one when the list is populated using the onCreateView when the app starts(white text) and the other is whenever the SetList() method is called
http://i.stack.imgur.com/QHNEL.png
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
ListView lv = (ListView) rootView.findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(((MainActivity)getActivity()).getApplicationContext(), android.R.layout.simple_list_item_1,((MainActivity)getActivity()).Logs);
lv.setAdapter(adapter);
return rootView;
http://i.stack.imgur.com/8uTe1.png
public void SetList()
ListView lv = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,Logs);
lv.setAdapter(adapter);
Problem solved by changing
ArrayAdapter<String> adapter = new ArrayAdapter<String>(((MainActivity)getActivity()).getApplicationContext(), android.R.layout.simple_list_item_1,((MainActivity)getActivity()).Logs);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(((MainActivity)getActivity()).getBaseContext(), android.R.layout.simple_list_item_1,((MainActivity)getActivity()).Logs);
it seems like for some reason ((MainActivity)getActivity()).getApplicationContext()
returns a different default text color than ((MainActivity)getActivity()).getBaseContext()
Change
ArrayAdapter<String> adapter = new ArrayAdapter<String>(((MainActivity)getActivity()).getApplicationContext(), android.R.layout.simple_selectable_list_item,((MainActivity)getActivity()).Logs);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(((MainActivity)getActivity()).getApplicationContext(), android.R.layout.simple_list_item_1,((MainActivity)getActivity()).Logs);
in onCreateView
. The problem is that you are using 2 different layouts in the adapter. Using android.R.layout.simple_list_item_1
should give you TextView
with black text the first time too.
–
try this, Override getView method and set text color like this
countryadapter = new ArrayAdapter<String>(CreateGroupsActivity.this,
android.R.layout.simple_spinner_item,
CommonListClass.countryName) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = super.getView(position, convertView, parent);
((TextView) v).setTextColor(getResources().getColor(R.color.black_color));
return v;
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
View v = super.getDropDownView(position, convertView, parent);
((TextView) v).setTextColor(getResources().getColor(R.color.black_color));
return v;
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.