I have 2 listview. I want when the activity starts first row of the both the listview to be selected by default.I googled up i found this
onewaydata=new One
Try this, it should do the trick:
your_list_view.post(new Runnable() {
@Override
public void run() {
your_list_view.setSelection(0);
}
});
UPDATE: Please take a look at this
class YourAdapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup arg2) {
View view = convertView;
if(position == 0){
// This is the first item, you need to select this
view.setSelected(true);
}
// Do whatever you want here
return view;
}
}
In XML:
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
In your item-row-xml:
And last you need to implement your own item_row_select with the state of "selected".
Hope this helps.