gpt4 book ai didi

java - 旋转手机取消选择列表中的项目 查看

转载 作者:行者123 更新时间:2023-12-02 12:18:43 29 4
gpt4 key购买 nike

当我旋转手机时, ListView 中选定的项目将被取消选择。这是我的适配器。我只想更改所选项目的颜色(仅是单个选择),当我旋转手机时,我想查看我选择的内容。现在,当我旋转手机时,我看不到所选项目。

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>

我将其添加到 list 中:

    android:configChanges="keyboardHidden|orientation|screenSize"

当我旋转手机时,onCreate 不起作用

最佳答案

将您的 Activity 启动模式设置为singleTop:

<activity android:launchMode="singleTop" >
</activity>

并覆盖onNewIntent:

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);

//setIntent(intent);
}

这将重用 Activity 堆栈中的 Activity 。

关于java - 旋转手机取消选择列表中的项目 查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45962321/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com