我需要在我的RecyclerView中顯示一些卡片中的mapView。所以我遵循一些教程和我在RecyclerView使它:可以刪除回收站視圖中的以前的項目嗎?
public class ShowParkAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
{
private List<Location> locations;
private Context context;
public ShowParkAdapter(List<Location> locations,Context context)
{
this.locations = locations;
this.context = context;
}
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
MapViewListItemView mapViewListItemView = new MapViewListItemView(context);
mapViewListItemView.mapViewOnCreate(null);
ParkAdapter parkHolder = new ParkAdapter(mapViewListItemView);
return parkHolder;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
ParkAdapter mHolder = (ParkAdapter)holder;
StringBuilder type, createdAt, stateAt, segnalationAt;
String locate;
Location location = locations.get(position);
mHolder.setmMapViewListItemViewPutMarkers(location.getLatitude(),location.getLongitude(),location.getType());
mHolder.mapViewListItemViewOnResume();
locate = location.getType();
type = new StringBuilder(mHolder.tipologia.getText().toString().trim());
type.append(" ").append(locate);
mHolder.tipologia.setText(type.toString());
createdAt = new StringBuilder(mHolder.data.getText().toString().trim());
createdAt.append(" ").append(location.getCreatedAt());
mHolder.data.setText(createdAt.toString());
stateAt = new StringBuilder(mHolder.state.getText().toString().trim());
stateAt.append(" ").append("verificato");
mHolder.state.setText(stateAt.toString());
segnalationAt = new StringBuilder(mHolder.segnalations.getText().toString().trim());
segnalationAt.append(" ").append("0");
mHolder.segnalations.setText(segnalationAt.toString());
notifyDataSetChanged();
}
public int getItemCount()
{
return locations.size();
}
private class ParkAdapter extends RecyclerView.ViewHolder
{
private MapViewListItemView mMapViewListItemView;
TextView tipologia, data,state,segnalations;
public ParkAdapter(final MapViewListItemView mapViewListItemView)
{
super(mapViewListItemView);
mMapViewListItemView = mapViewListItemView;
tipologia = (TextView)mapViewListItemView.findViewById(R.id.type);
data = (TextView)mapViewListItemView.findViewById(R.id.addedAt);
state = (TextView)mapViewListItemView.findViewById(R.id.state);
segnalations = (TextView)mapViewListItemView.findViewById(R.id.signal);
state.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showErrorMessage(context,mapViewListItemView.getResources().getString(R.string.infoStato));
}
});
segnalations.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showErrorMessage(context,mapViewListItemView.getResources().getString(R.string.infoSign));
}
});
}
private void showErrorMessage(Context mContext,String message)
{
new AlertDialog.Builder(mContext)
.setMessage(message)
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
}
}).create().show();
}
public void setmMapViewListItemViewPutMarkers(double latitude, double longitude,String type)
{
if(mMapViewListItemView != null)
mMapViewListItemView.putMarkers(latitude,longitude,type);
}
public void mapViewListItemViewOnCreate(Bundle savedInstanceState) {
if (mMapViewListItemView != null) {
mMapViewListItemView.mapViewOnCreate(savedInstanceState);
Log.d("map","oncreate");
}
}
public void mapViewListItemViewOnResume() {
if (mMapViewListItemView != null) {
mMapViewListItemView.mapViewOnResume();
Log.d("map","onresume");
}
}
public void mapViewListItemViewOnPause() {
if (mMapViewListItemView != null) {
mMapViewListItemView.mapViewOnPause();
Log.d("map","onpause");
}
}
public void mapViewListItemViewOnDestroy() {
if (mMapViewListItemView != null) {
mMapViewListItemView.mapViewOnDestroy();
Log.d("map","ondestroy");
}
}
public void mapViewListItemViewOnLowMemory() {
if (mMapViewListItemView != null) {
mMapViewListItemView.mapViewOnLowMemory();
}
}
public void mapViewListItemViewOnSaveInstanceState(Bundle outState) {
if (mMapViewListItemView != null) {
mMapViewListItemView.mapViewOnSaveInstanceState(outState);
}
}
}
}
我嘗試使用notifyDataSetChanged();
,但我給了同樣的錯誤。 我該如何解決這個問題? 感謝
*我如何解決這個問題?*通過分析ng **你的** ......你將新的文字追加到舊的每一次查看被重用......它根本沒有做出任何的感覺 – Selvin
所以你是一個真正的!我在哪裏添加新的文字到舊的? – nani
你是否理解你的代碼...請使用調試鴨並逐行解釋它 – Selvin