从ListView到TextView(Parse)

时间:2014-08-23 22:28:44

标签: java android android-layout android-fragments parse-platform

有了支持,我已经设法从解析中检索列表和图像,但是,我希望能够检索可以在textview中显示的字符串,与listview相反,因为我没有理由使用列表检索一个项目。此外,我有一个问题,列表视图可以在触摸时滚动,所以我想如果它只是一个文本视图会更好。

下面是检索listview的代码,我希望能够在textview中显示该信息。在这种情况下,我试图从满足各种条件设置的用户的解析的ActivityName列中检索信息。

ParseQuery<ParseUser> query = ParseUser.getQuery();

        // query.whereEqualTo("ActivityName",userActivitySelectionName);

        query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
                .getObjectId());
        // users with Gender = currentUser.Looking_Gender
        query.whereEqualTo("Gender", userLookingGender);
        // users with Looking_Gender = currentUser.Gender
        query.whereEqualTo("Looking_Gender", userGender);
        query.setLimit(1);
        query.whereEqualTo("ActivityName", activityName);
        // query.whereGreaterThanOrEqualTo("Age", minimumAge);
        // query.whereLessThanOrEqualTo("Age", maximumAge);
        query.orderByDescending("Name");

        Log.d(Constants.LOG, "");



        query.findInBackground(new FindCallback<ParseUser>() {



            public void done(List<ParseUser> userlistactivityname, ParseException e) {
                if (e == null) {
                    for (int i = 0; i < userlistactivityname.size(); i++) {
                        names.add(userlistactivityname.get(i).get("ActivityName").toString());
                    }
                    usersListActivityname = (ListView) getActivity().findViewById(
                            R.id.userlistactivityname);
                    namesArrayAdapter = new ArrayAdapter<String>(getActivity()
                            .getApplicationContext(), R.layout.user_list_item,
                            names);
                    usersListActivityname.setScrollContainer(false);
                    usersListActivityname.setClickable(false);

                    usersListActivityname.setAdapter(namesArrayAdapter);



                } else {

                }
                }
            });

下面是XML

<ListView
        android:id="@+id/userlistactivityname"
        android:layout_width="220dp"
        android:layout_height="50dp"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="7dp"
        android:layout_toLeftOf="@+id/imageView2"
        android:divider="@null" >
    </ListView>

更新

 query2.findInBackground(new FindCallback<ParseUser>() {



            public void done(List<ParseUser> userlistactivityname, ParseException e) {
                if (e == null) {
                    TextView text=(TextView)getActivity().findViewById(R.id.userlistactivityname);
                    text.get("ActivityName").setText();



                } else {

                }
                }
            });

XML

<TextView
        android:id="@+id/userlistactivityname"
        android:layout_width="220dp"
        android:layout_height="50dp"
        android:cacheColorHint="@android:color/transparent"
        android:layout_below="@+id/textView1"
        android:layout_toLeftOf="@+id/imageView2"
        android:divider="@null" >
    </TextView>

更新: textview无法强制转换为android.widget.listview

query2.findInBackground(new FindCallback<ParseUser>() {



            public void done(List<ParseUser> userlistactivityname, ParseException e) {
                if (e == null) {
                     for (int i = 0; i < userlistactivityname.size(); i++) {
                         mUserActivityNameRetrieved = (TextView) getActivity().findViewById(R.id.userlistactivityname);


                         mUserActivityNameRetrieved.setText(userlistactivityname.get(i).get("ActivityName").toString());                     }


                } else {

                }
                }
            });

1 个答案:

答案 0 :(得分:1)

只需将ListView设为TextView,然后在Java中对TextView进行数据绑定,在TextView上调用.setText()方法。此外,由于您将查询限制设置为1,因此无需订购查询。行query.orderByDescending("Name");是不必要的