RecyclerView에 카드의 mapView가있는 일부 CardViews를 표시해야합니다. 그래서 몇 가지 튜토리얼을 따라 내 RecyclerView에서 그것을 만든 :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 ** your ** ... 뷰가 재사용 될 때마다 새 텍스트를 낡은 것에 추가하고 있습니다 ... 전혀 감각을 만들지 못합니다 – Selvin
그래서 당신은 천재적입니다! 그리고 나는 어디에 새로운 텍스트를 추가 하는가? – nani
코드를 이해하고 있습니까? 디버깅 오리를 사용하여 줄 단위로 설명하십시오. – Selvin