Я заполняю список с помощью элементов parse.com. Он работал отлично не так давно, а затем по какой-то причине, когда я изменился с eclipse на андроид-студию, он начал показывать только последний элемент.Andrioid listview только показывает последний элемент
адаптер
public class MyCustomAdapter extends ParseQueryAdapter<ParseObject> {
public MyCustomAdapter(Context context) {
super(context, "Comments", R.layout.comments_listview_item);
}
@Override
public View getItemView(ParseObject comment, View view, ViewGroup parent) {
view = View.inflate(getApplicationContext(), R.layout.comments_listview_item, null);
mListViewReferences(view);
loadComments();
commenttext.setText(comment.getString("Comment"));
commentersUserName.setText(comment.getString("Commenter"));
return super.getItemView(comment, view, parent);
}
/**
* Set References
*/
private void mListViewReferences(final View view) {
commentersUserName = (TextView) view.findViewById(R.id.commentersUserName);
commenttext = (TextView) view.findViewById(R.id.commenttext);
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:padding="0dp">
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="0dp"
android:background="@drawable/actionmenubackground">
<TextView
android:id="@+id/commenttext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="@+id/comentFullName"
android:text="COMMENTS"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold" />
<ImageButton
android:id="@+id/backButton"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="0dp"
android:background="@null"
android:src="@drawable/back_arrow" />
<TextView
android:id="@+id/comentFullName"
android:layout_width="2dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/backButton"
android:background="#E0E0E0" />
</RelativeLayout>
<EditText
android:id="@+id/setComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/submitComment"
android:layout_toLeftOf="@+id/submitComment"
android:ems="10"
android:hint="Add a comment" />
<ImageButton
android:id="@+id/submitComment"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/actionmenubackground"
android:src="@drawable/commentsubmitarrow" />
<View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/setComment"
android:background="@color/green" />
<ListView
android:id="@+id/commentsListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:divider="@null"
android:dividerHeight="5dp"
android:clickable="false"
android:listSelector="@android:color/transparent"
android:layout_below="@+id/relativeLayout1"
android:layout_above="@+id/setComment"
android:choiceMode="none" />
</RelativeLayout>
Вот мой метод loadComments();
void loadComments() {
runOnUiThread(new Runnable() {
@Override
public void run() {
MyCustomAdapter adapter = new MyCustomAdapter(getApplicationContext());
commentsListView.setAdapter(adapter);
}
});
}
В этой строке 'вернуть super.getItemView (комментарий, вид, родитель);' вы должны делать 'обратный вид;'. –
@MikeLaren нет, это не так. – user123859