다음은 listview의 사용자 정의 행에 대한 레이아웃입니다.ListView가 이상하게 업데이트됩니다.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/layoutTop"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Well Hello Motherfucker"
android:id="@+id/geventProfileName"
android:textSize="20sp"
android:paddingLeft="50dp"/>
</RelativeLayout>
<FrameLayout
android:id="@+id/layoutBottom"
android:layout_width="match_parent"
android:layout_height="300dp"
android:alpha="1"
android:layout_below="@+id/layoutTop"
android:layout_alignParentStart="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/no_picture"
android:id="@+id/geventEventPhoto"
android:layout_gravity="top|left"
android:alpha="1"/>
<TextView
android:layout_width="350dp"
android:layout_height="wrap_content"
android:text="asfda"
android:layout_gravity="center|left"
android:textSize="35sp"
android:textColor="#FFF"
android:textAllCaps="true"
android:id="@+id/geventTitle"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Read More"
android:textColor="@color/black"
android:id="@+id/geventReadMoreButton"
android:background="@drawable/readtab"
android:paddingTop="10dp"
android:paddingLeft="20dp"
android:layout_gravity="bottom|right"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:id="@+id/geventDescription"
android:text=""
android:textColor="@color/black"
android:layout_gravity="top|left"/>
<TextView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="@+id/geventDetails"
android:text=""
android:textSize="20sp"
android:textColor="#FFF"
android:layout_gravity="bottom|left"
/>
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/layoutBottom"
android:orientation="horizontal"
android:background="#9E9E9E"
android:padding="5dp"
android:layout_marginTop="5dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:id="@+id/numberOfLikesGEvent"
android:textColor="@color/black"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/numberOfLikesGEvent"
android:id="@+id/likeTextViewGEvent"
android:layout_marginLeft="10dp"
android:textColor="@color/black"
android:text="Like"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/dislikeTextViewGEvent"
android:layout_marginRight="10dp"
android:id="@+id/numberOfDislikesGEvent"
android:textColor="@color/black"
android:text="200"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dislikeTextViewGEvent"
android:text="Dislike"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="0dp"
android:textColor="@color/black"/>
</RelativeLayout>
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/photo"
app:civ_border_width="2dp"
app:civ_border_color="#FFF"/>
그리고 이것은 내 CustomAdapter
public class CustomAdapter extends ArrayAdapter<GEvent> {
boolean hasLiked;
boolean hasDisliked;
FirebaseUser fbUser;
ArrayList<String> uids;
ArrayList<String> dUids;
GEvent currentEvent;
private TextView likeTextView;
private TextView numberOfLikes;
private TextView dislikeTextView;
private TextView numberOfDislikes;
private TextView readMoreButton;
private TextView eventDetails;
private TextView titleGevent;
private ImageView eventPhoto;
private TextView profileName;
private TextView descriptionGevent;
private String description;
private String titleForGEvent;
private String detailsGEvent;
private boolean hasLoaded=true;
private de.hdodenhof.circleimageview.CircleImageView circleImageView;
private Context mContext;
private boolean wantsToReadMore=false;
String profilePhotoLink;
PopupWindow pw;
public CustomAdapter(Context context, GEvent[] resource) {
super(context, R.layout.custom_row , resource);
this.mContext = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getContext());
final View customView = inflater.inflate(R.layout.example,parent,false);
final GEvent gEvent = getItem(position);
currentEvent = gEvent;
firebaseAuth = FirebaseAuth.getInstance();
uid = firebaseAuth.getCurrentUser().getUid();
titleGevent = (TextView) customView.findViewById(R.id.geventTitle);
descriptionGevent = (TextView) customView.findViewById(R.id.geventDescription);
profileName = (TextView) customView.findViewById(R.id.geventProfileName);
likeTextView = (TextView) customView.findViewById(R.id.likeTextViewGEvent);
numberOfLikes = (TextView) customView.findViewById(R.id.numberOfLikesGEvent);
numberOfDislikes =(TextView) customView.findViewById(R.id.numberOfDislikesGEvent);
dislikeTextView = (TextView) customView.findViewById(R.id.dislikeTextViewGEvent);
readMoreButton = (TextView) customView.findViewById(R.id.geventReadMoreButton);
eventPhoto = (ImageView) customView.findViewById(R.id.geventEventPhoto);
eventDetails = (TextView)customView.findViewById(R.id.geventDetails);
circleImageView = (CircleImageView) customView.findViewById(R.id.profile_image);
description = gEvent.getDescription();
detailsGEvent = gEvent.getgEventDate()+"\n"+gEvent.getgEventTime()+"\n"+gEvent.getVenue1()+"\n"+gEvent.getVenue2()+"\n"+gEvent.getContactEmail()+"\n"+gEvent.getContactPhoneNumber();
titleForGEvent = gEvent.getTitle();
if(gEvent.isHasPhoto()){
hasLoaded= false;
readMoreButton.setText("Loading");
}
readMoreButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(hasLoaded) {
Log.i("CA","Entered hasLoaded Function");
readMoreFunction();
}
else
Toast.makeText(mContext,"Loading....",Toast.LENGTH_LONG).show();
}
});
titleGevent.setText(gEvent.getTitle());
String uuid = gEvent.getUuid();
Boolean hasPhoto = gEvent.isHasPhoto();
profileName.setText(gEvent.getProfileUsername());
if(hasPhoto) {
final long ONE_MEGABYTE = 1024 * 1024 * 5;
pathRef.getBytes(ONE_MEGABYTE).addOnSuccessListener(new OnSuccessListener<byte[]>() {
@Override
public void onSuccess(byte[] bytes) {
Bitmap picturel = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
ImageView imageView = (ImageView) customView.findViewById(R.id.geventEventPhoto);
Drawable d = new BitmapDrawable(mContext.getResources(),picturel);
imageView.setBackground(d);
Log.i("CA","Entered hasRetrieved Photo and update hasLoaded");
readMoreButton.setText("Read More");
hasLoaded=true;
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
Log.i("Error","Couldn't Download");
}
});
}
return customView;
}
공공 무효 readMoreFunction() {
Log.i("CA","Entered readMoreFunction Function");
if(wantsToReadMore){ //wants to read less now
Log.i("CA","Entered Read Less Function");
eventPhoto.setAlpha(1f);
descriptionGevent.setText("");
eventDetails.setText("");
readMoreButton.setText("Read More");
titleGevent.setText(titleForGEvent);
wantsToReadMore=false;
}
else{ //Wants to read more
Log.i("CA","Entered Read More Function");
eventPhoto.setAlpha(0.5f);
descriptionGevent.setText(description);
eventDetails.setText(detailsGEvent);
titleGevent.setText("");
readMoreButton.setText("Read Less");
wantsToReadMore=true;
}
입니다
내 문제는이 CustomAdapter를 호출 할 때마다 하나의 목록 항목 만 있으면 완벽하게 작동하지만 여러 목록 항목이있을 때마다 어댑터가 이상하게 작동하기 시작한다는 것입니다. 예를 들어, 두 개의 항목이있을 때마다 첫 번째 항목에 대해 "자세히보기"버튼을 누르면 두 번째 항목에 대해 트리거됩니다. 로그에서 작업중인 데이터가 첫 번째 항목임을 나타냅니다.
두 개 이상의 항목이있는 경우 위의 패턴이 관찰됩니다. 즉, 주어진 항목의 '자세히보기'버튼을 클릭 할 때마다 목록보기의 다음 항목을 트리거합니다. 때로는 이미지가로드되거나 "자세히 알아보기"버튼이 응답하지 않은 경우에도 "로드 중"에 멈추는 경우가 있습니다. 나는 지난 2 일 동안 내 머리를 치며 버그를 찾고있다. 너희들이 나를 도울 수 있기를 바랍니다. 사전에 감사합니다.
추 신 : "Load More"버튼이 작동하지 않습니다. 실례합니다.
모델 내에서 각 항목의 상태를 저장해야합니다 (자세히 읽었거나 읽지 않은 경우). 또한'readMoreFunction' 메쏘드는 오래된 데이터를 사용하고 있습니다. 항상 getView의 마지막 반복의 값을가집니다. –
현재 데이터를 사용하고 getView에서 부실 데이터를 방지하려면 어떻게해야합니까? – THGRoy