RecyclerViewに、カード内にmapViewを持つCardViewをいくつか表示する必要があります。だから私はいくつかのチュートリアルに従うと、私は私の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();
を使用しようが、私は同じエラーを与えます。 この問題をどうやって解決できますか? おかげ
に同じ:
それとも単に:
そして国際空港で:
PS *どうすればこの問題を解決できますか? ng **あなたの** ...ビューが再利用されるたびに新しいテキストを古いものに追加しています...それは全く感覚的ではありません – Selvin
あなたは幻想的です!私はどこに新しいテキストを追加するのですか? – nani
あなたのコードはまったく理解していますか?デバッグ用のダックを使用して、行ごとに説明してください。 – Selvin