1

My requirement is highlight first row form list when the activity load(initial listview should be highlighted.).

I have done like this

  @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sales_routes);

    ArrayList<Object> routeList = getWmRoute();
    ArrayList<String> routhPath = new ArrayList<String>();
    for(int i = 0; i<routeList.size();i++){
        routhPath.add(((WMRoute) routeList.get(i)).getDescription());
    }
    this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_two_column, R.id.FROM_CELL, routhPath));
    ListView list = getListView();
    list.setSelected(true);
    list.setSelection(0);
    list.getItemAtPosition(0);
    System.out.println(" ========= "  +  list.getItemAtPosition(0));
    list.setFocusable(true);
    list.requestFocus();

This is not selected that particular row.

I have to select first row as well as select the radio button also.

enter image description here Please help me.

please help me this.

Thanks in advance.

Piraba
  • 6,974
  • 17
  • 85
  • 135

1 Answers1

1

You can try

requestFocus() method;

list.getChildAt(0).setSelection(true); method may be getChildAtPosition(0).See what is available.I am confused

bharath
  • 14,283
  • 16
  • 57
  • 95
Rasel
  • 15,499
  • 6
  • 40
  • 50
  • My case "list.getItemAtPosition(0)" its return "Mt.Lavinia 1". Not select the radio button – Piraba Jul 18 '11 at 12:18
  • it is the text of radio button.You have to set is as selected – Rasel Jul 18 '11 at 12:21
  • try list.getItemAtPosition(0).toggle(); – Rasel Jul 18 '11 at 12:23
  • even either of condition not working.see this my code - this.setListAdapter(new ArrayAdapter(this, R.layout.list_two_column, R.id.FROM_CELL, routhPath)); ListView list = getListView(); list.requestFocus(); list.setSelected(true); list.setSelection(0); list.setFocusable(true);. Is there any order for this? – Piraba Jul 18 '11 at 12:26
  • try with list.getItemAtPosition(0).toggle(); – Rasel Jul 18 '11 at 12:27
  • View v=(RadioButton) list.getChildAt(0);v.toggle(); – Rasel Jul 18 '11 at 12:28
  • "list.getItemAtPosition(0)" its return "Mt.Lavinia 1" so may be wrong in the radiobutton xml part – Piraba Jul 18 '11 at 12:45
  • try with childAt.it will give you object.print it to see whether it is string or RadioButton.You need to get the child as RadioButton so that you can toggle it – Rasel Jul 18 '11 at 12:47
  • Thank Rasel for your help. I have selected checkbox. This link was help for me http://stackoverflow.com/questions/5303502/listview-setitemchecked-doesnt-work – Piraba Jul 20 '11 at 05:11