0

particular list item select to set bgcolor for list item ,when scroll down listview to automatically set color for other item, my sample code suggestion and help me.(this code v.setbackgroundcolor(Color.gray) using problem occur,so clear the problem)

public class MainActivity extends Activity {    
ListView list;
ArrayAdapter<String> adapter;
ArrayList<String>listitem=new ArrayList<String>();
String val;
String[] list_number={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    list=(ListView)findViewById(R.id.listView1);
    adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list_number);
    list.setAdapter(adapter);

     list.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View v, int position,
                    long id) {
                   String selectedFromList =(list.getItemAtPosition(position).toString());                  
                if(listitem.isEmpty())
                {
                    listitem.add(selectedFromList);
                    Set<String> primesWithoutDuplicates = new LinkedHashSet<String>(listitem);
                    listitem.clear();                  
                    listitem.addAll(primesWithoutDuplicates);
                    v.setBackgroundColor(Color.GRAY);
                    }
                else
                {
                        if( listitem.contains(selectedFromList))
                        {
                            listitem.remove(selectedFromList);
                             v.setBackgroundColor(Color.WHITE);
                    }
                        else 
                        {
                            listitem.add(selectedFromList);                                            
                            Set<String> primesWithoutDuplicates = new LinkedHashSet<String>(listitem);
                            listitem.clear();                  
                            listitem.addAll(primesWithoutDuplicates);
                            v.setBackgroundColor(Color.GRAY);
                        }                                                   
                    }               
            }
        });     
}
}
benbenw
  • 723
  • 7
  • 20
dhineshkumar
  • 51
  • 1
  • 6
  • in if condition instead of this **listitem.contains(selectedFromList)** try this **listitem.getSelectedItem().equals(selectedFromList)** – brahmy adigopula Sep 02 '16 at 08:37
  • My problem was first list item selected to set bgcolor item,but listview scroll down automatically set bgcolor for other item, this code apply --> v.setBackgroundColor(Color.GRAY); scroll down another list item set bgcolor automatically,please help me – dhineshkumar Sep 02 '16 at 09:50
  • try this too bro..http://stackoverflow.com/questions/16189651/android-listview-selected-item-stay-highlighted..i will help you keep texting if you face any problem.. – brahmy adigopula Sep 02 '16 at 09:56
  • when select list item set bgcolor,then scroll down listview other item set bgcolor ,please any sample send me.. – dhineshkumar Sep 02 '16 at 10:48
  • particular list item selected to color set for particular list row,when scroll the listview automatically set color to list item,how to problem solve please help me.sample code send me. – dhineshkumar Sep 03 '16 at 06:38
  • try this bro..http://stackoverflow.com/questions/16976431/change-background-color-of-selected-item-on-a-listview – brahmy adigopula Sep 03 '16 at 06:52
  • my problem was listview scroll down other list set color. view.setbackgroundcolor(Color.gray) and list.getchildat(position).setbackgroundcolor(color.gray);//this two code using set color for list item,but scroll the listview automatically set color how problem solve pls help me. – dhineshkumar Sep 03 '16 at 06:58
  • please help me, my problem was list item select to background set when listview scroll down automatically other list item set bgcolor,my sample posted and code analysis to reply me.. – dhineshkumar Sep 21 '16 at 07:04
  • http://stackoverflow.com/questions/16189651/android-listview-selected-item-stay-highlighted...refere this to set back ground color for selected item.@dhineshkumar – brahmy adigopula Sep 21 '16 at 11:39
  • refer here i edited the code of your's..http://pastebin.com/h4DuZExS – brahmy adigopula Sep 21 '16 at 11:56
  • listview display 25 list ,currently first 15 list display for listview and another 10 list down,my problem when 1,2,3 list select to color set list item and automaticallly 16,17,18 list item set color ,how to avoid this problem please help me and give me solution. – dhineshkumar Oct 03 '16 at 03:55
  • try to match the position number of the list item and set color for that particular position. – brahmy adigopula Oct 03 '16 at 04:44
  • 25 list item display for listview , current first 15 item display another list item hide,listview position 1,2& 3 select to color set when listview scroll down position 16,17&18 automatically set color ,my code post and suggestion tell me. – dhineshkumar Oct 03 '16 at 04:59
  • any sample send me – dhineshkumar Oct 03 '16 at 05:00
  • http://stackoverflow.com/questions/18917214/change-background-colour-of-current-listview-item-in-adapter-getview-method check out here – brahmy adigopula Oct 03 '16 at 05:03
  • list item click to select color view and same list item click to color remove ,but my problem(ex: 20 list item display for listview, first listview 10 list item display another 10 list item hide,when list item click 1,2&3 set color but listview scroll down automatically list item 11,12&13 set color ) this code using to problem occur please help me and related sample code send me. – dhineshkumar Oct 03 '16 at 05:23

0 Answers0