Piraba
Piraba

Reputation: 7014

Hightlight the first row from the listview

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.

Upvotes: 1

Views: 767

Answers (1)

Rasel
Rasel

Reputation: 15477

You can try

requestFocus() method;

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

Upvotes: 1

Related Questions