我使用parse.com中的項目填充listview。它不久前工作正常,然後由於某種原因,一旦我從eclipse更改爲android工作室,它開始只顯示最新的項目。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(評論,觀點,母體);'你應該做'返回查看;'。 – 2014-10-06 05:37:25
@MikeLaren nope,那不是。 – user123859 2014-10-06 05:38:53