當我旋轉手機時,所選項目在列表視圖中未被選中。這是我的適配器。我只是想改變選定項目的顏色(這是一個單一的選擇),當我旋轉手機,我想看看我選擇什麼。現在,當我旋轉手機時,我看不到選擇的項目。旋轉電話在列表中取消選擇我的項目查看
public class MainAdapter extends BaseAdapter {
private LayoutInflater inflater;
private Context context;
ArrayList<RowEntity> rowEntities;
public MainAdapter(Context context, ArrayList<RowEntity> rowEntities) {
this.context = context;
this.rowEntities = rowEntities;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return rowEntities.size();
}
@Override
public Object getItem(int position) {
return rowEntities.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.main_row_holder, null);
holder.address = (TextView) convertView.findViewById(R.id.address);
holder.distance = (TextView) convertView.findViewById(R.id.tv_distance);
holder.description = (TextView) convertView.findViewById(R.id.description);
holder.name = (TextView) convertView.findViewById(R.id.name);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
RowEntity rowEntity = rowEntities.get(position);
if(rowEntity != null){
holder.address.setText(rowEntity.getAddress());
holder.address.setText(rowEntity.getAddress());
holder.distance.setText(rowEntity.getDistance() +"");
}
return convertView;
}
private class ViewHolder{
TextView address;
TextView distance;
TextView description;
TextView name;
}
}
這是我在佈局的ListView:
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
android:listSelector="@drawable/background_listview"
android:visibility="visible"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="@+id/bottomPanel" />
這是background_listview.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/white_background"
android:state_pressed="true" />
<item android:drawable="@color/primary_color"
android:state_focused="false" />
</selector>
我添加此清單上:
android:configChanges="keyboardHidden|orientation|screenSize"
時我旋轉手機上創建不是工作king