我有一个RecycleView
,它显示了将来会发生的事件,并且工作正常(所有信息都显示出来)但是之后我在运行它后再添加了2个按钮我减少了事件,我不知道为什么(我没有改变java文件中的任何代码)
这是我的代码:
private void setupAdaptaterNew() {
mPostAdapterNew = new FirebaseRecyclerAdapter<Post, PostViewHolder>(
Post.class,
R.layout.item_layout_evenimente,
PostViewHolder.class,
mPostRef
) {
@Override
public void populateViewHolder(final PostViewHolder viewHolder, final Post model, final int position) {
final int EndOra = viewHolder.setEndOra(model.getEndOra());
final long EndZi = viewHolder.setEndZi(model.getEndZi());
final int EndLuna = viewHolder.setEndLuna(model.getEndLuna());
final int EndAn = viewHolder.setEndAn(model.getEndAn());
final ContentResolver cr = getApplicationContext().getContentResolver();
final ContentValues values = new ContentValues();
final ContentResolver crReminder = getApplicationContext().getContentResolver();
final ContentValues[] valuesReminder = {new ContentValues()};
final Uri[] event = new Uri[1];
final String headline = viewHolder.setHeadline(model.getHeadline());
final String locatie = viewHolder.setStrada(model.getStrada());
final String organizator = viewHolder.setOrganizator(model.getOrganizator());
final Button btnDeleteEvent = viewHolder.itemView.findViewById(R.id.BtnNuParticip);
final Button btnAddEvent = viewHolder.itemView.findViewById(R.id.BtnParticip);
final Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR, EndOra);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.MONTH, EndLuna);
cal.set(Calendar.DAY_OF_MONTH, (int) EndZi);
cal.set(Calendar.YEAR, EndAn);
if (Calendar.getInstance().before(cal)) {
StorageReference storageReference = FirebaseStorage.getInstance().getReferenceFromUrl(model.getImageUrl());
Glide.with(Evenimente.this)
.using(new FirebaseImageLoader())
.load(storageReference)
.into(viewHolder.postIV);
viewHolder.setHeadline(model.getHeadline());
viewHolder.setZiua(model.getZiua());
viewHolder.setLuna(model.getLuna());
viewHolder.setOra(model.getOra());
viewHolder.setOrganizator(model.getOrganizator());
viewHolder.setCategoria(model.getCategoria());
viewHolder.setStrada(model.getStrada());
viewHolder.setLocalitatea(model.getLocalitatea());
viewHolder.setPostDescriere(model.getDescriere());
} else {
viewHolder.itemView.setVisibility(View.GONE);
viewHolder.itemView.setLayoutParams(new RecyclerView.LayoutParams(0, 0));
}
btnAddEvent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED ||
ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), "Permisii insuficiente.\n Va rugam sa activati permisiunea de CALENDAR", Toast.LENGTH_LONG).show();
} else {
long startMillis = 0;
long endMillis = 0;
//Start and End of event date
Calendar beginTime = Calendar.getInstance();
beginTime.set(EndAn, EndLuna, (int) EndZi, EndOra, 0);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(EndAn, EndLuna, (int) EndZi, EndOra, 0);
endMillis = endTime.getTimeInMillis();
//Add Values
values.put(Events.DTSTART, startMillis);
values.put(Events.TITLE, headline);
values.put(Events.DESCRIPTION, "Description"); //TODO change description here!
TimeZone timeZone = TimeZone.getDefault();
values.put(Events.EVENT_TIMEZONE, timeZone.getID());
values.put(Events.CALENDAR_ID, 1);
values.put(Events.DTEND, endMillis);
values.put(Events.EVENT_LOCATION, locatie);
values.put(Events.ORGANIZER, organizator);
event[0] = cr.insert(Events.CONTENT_URI, values);
valuesReminder[0].put(CalendarContract.Reminders.DTSTART, startMillis);
Uri REMINDERS_URI_DAY = Uri.parse(getCalendarUriBase(true) + "reminders");
valuesReminder[0] = new ContentValues();
valuesReminder[0].put("event_id", Long.parseLong(event[0].getLastPathSegment()));
valuesReminder[0].put("method", 1);
valuesReminder[0].put("minutes", 1440);
Uri uriReminderDay = crReminder.insert(REMINDERS_URI_DAY, valuesReminder[0]);
Uri REMINDERS_URI_HOUR = Uri.parse(getCalendarUriBase(true) + "reminders");
valuesReminder[0] = new ContentValues();
valuesReminder[0].put("event_id", position);
valuesReminder[0].put("method", 1);
valuesReminder[0].put("minutes", 120);
Uri uriReminder = crReminder.insert(REMINDERS_URI_HOUR, valuesReminder[0]);
createDialogAddEvent(headline);
btnDeleteEvent.setVisibility(View.VISIBLE);
btnAddEvent.setVisibility(View.GONE);
}
}
});
btnDeleteEvent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri deleteUri = null;
deleteUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, Long.parseLong(event[0].getLastPathSegment()));
int rows = getContentResolver().delete(deleteUri, null, null);
btnDeleteEvent.setVisibility(View.GONE);
btnAddEvent.setVisibility(View.VISIBLE);
//Create Dialog;
createDialogDeleteEvent(headline);
}
});
}
};
}
private String getCalendarUriBase(boolean eventUri) {
Uri calendarURI = null;
try {
if (android.os.Build.VERSION.SDK_INT <= 7) {
calendarURI = (eventUri) ? Uri.parse("content://calendar/") : Uri.parse("content://calendar/calendars");
} else {
calendarURI = (eventUri) ? Uri.parse("content://com.android.calendar/") : Uri
.parse("content://com.android.calendar/calendars");
}
} catch (Exception e) {
e.printStackTrace();
}
return calendarURI.toString();
}
这是我的RecycleView模型:
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:gravity="center_vertical|right"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:gravity="center_vertical|right"
android:orientation="horizontal">
<!--Adding padding to the image view makes it easy to click -->
<LinearLayout
android:layout_width="60dp"
android:layout_height="90dp"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<TextView
android:id="@+id/text_ziua"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="10"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_luna"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="IAN"
android:textAlignment="center"
android:textSize="16sp" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="12dp"
android:text="---------"
android:textAlignment="center" />
<TextView
android:id="@+id/text_ora"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="10:00"
android:textAlignment="center"
android:textSize="12sp" />
</LinearLayout>
<ImageView
android:id="@+id/post_iv"
android:layout_width="90dp"
android:layout_height="90dp"
android:adjustViewBounds="false"
android:scaleType="centerCrop" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp">
<TextView
android:id="@+id/headline_event"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-5dp"
android:layout_marginRight="5dp"
android:text="Numele complet al evenimentului"
android:textColor="@android:color/holo_orange_dark"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView16"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_marginRight="5dp"
android:layout_marginTop="1.5dp"
android:adjustViewBounds="false"
android:cropToPadding="false"
app:srcCompat="?android:attr/listChoiceIndicatorSingle" />
<TextView
android:id="@+id/textView60"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Categoria:"
android:textSize="12sp" />
<TextView
android:id="@+id/text_categoria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Categoria"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView14"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_marginRight="5dp"
android:layout_marginTop="1.5dp"
android:adjustViewBounds="false"
android:cropToPadding="false"
app:srcCompat="@drawable/ic_people_black_24px" />
<TextView
android:id="@+id/text_organizator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Organizator:"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:id="@+id/text_strada"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="Strada:"
android:textAlignment="textEnd"
android:textSize="12sp" />
<TextView
android:id="@+id/text_localitatea"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="Localitatea"
android:textAlignment="textEnd"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/DescriereEveniment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:clickable="true"
android:autoLink="web"
android:visibility="gone" />
<Button
android:id="@+id/BtnParticip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Particip!"
/>
<Button
android:id="@+id/BtnNuParticip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nu m-ai particip"
/>
</LinearLayout>
所以你们可以告诉我为什么在xml文件末尾添加按钮whit id:BtnParticip / BtnNuParticipt后,某些值没有出现
答案 0 :(得分:1)
关闭CardView,你已经在xml文件的顶部打开了一个CardView,但没有关闭它。
将此添加到文件末尾
</android.support.v7.widget.CardView>
我希望有所帮助。
答案 1 :(得分:1)
您已将内部sub[] = new Double[9];
gr[] = new Double[9];
fin[] = new Double[9];
的高度设置为使用所有空格的LinearLayout
,并且按钮未显示。
试试这个:
match_parent