在Textview上显示Parse的信息

时间:2014-08-24 11:54:41

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

我正在尝试根据Parse的信息在文本视图中显示文本。例如,在这种情况下,我试图显示用户的活动名称。 以下是代码

 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 {

            }
            }
        });

布局

<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>

以下是整个代码

public interface Constants {
        String LOG = "com.dooba.beta";
    }

    private String currentUserId;
    private ArrayAdapter<String> namesArrayAdapter;
    private ArrayList<String> names;
    private ArrayList<String> age;
    private ArrayList<String> headline;
    private ArrayList<String> activityname;

    private ArrayList<Images> alProfilePicture;
    private ListView usersListName;
    private ListView usersListHeadline;
    private ListView usersListActivityname;

    private Button logoutButton;
    String userGender = ParseUser.getCurrentUser().getString("Gender");
    String activityName = ParseUser.getCurrentUser().getString("ActivityName");
    Number maxDistance = ParseUser.getCurrentUser().getNumber(
            "Maximum_Distance");
    String userLookingGender = ParseUser.getCurrentUser().getString(
            "Looking_Gender");
    Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
    Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
    Number userage = ParseUser.getCurrentUser().getNumber("Age");

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        setConversationsList();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment1_layout, container,
                false);

        Button newPage = (Button)view.findViewById(R.id.btnMatchConfirm);
        newPage.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), matchOptionActivity.class);
                startActivity(intent);
            }
        });


        return view;
    }

    private void setConversationsList() {
        currentUserId = ParseUser.getCurrentUser().getObjectId();
        names = new ArrayList<String>();
        age = new ArrayList<String>();
        headline = new ArrayList<String>();
        activityname = new ArrayList<String>();

        alProfilePicture = new ArrayList<Images>();

        // String userActivitySelectionName = null;

        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");


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

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

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

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

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

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

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

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

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

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




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

            @Override
            public void done(List<ParseUser> objects,ParseException e) {

                for(int i=0;i<objects.size();i++){
                    // Do whatever you need to extract object from "users"
                    ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
                    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");

                    ParseFile image = objects.get(i).getParseFile("ProfilePicture");


                    ParseImageView imageView = (ParseImageView) getView().findViewById(R.id.profilePictureresult);

                     // The placeholder will be used before and during the fetch, to be replaced by the fetched image
                     // data.
                     imageView.setPlaceholder(getResources().getDrawable(R.drawable.profile_pict));
                     imageView.setParseFile(image);
                     imageView.loadInBackground(new GetDataCallback() {
                       @Override
                       public void done(byte[] data, ParseException e) {
                           if (data != null) {
                               Log.i("ParseImageView", "Fetched: " + data.length);
                             } else {
                               Log.e("ParseImageView", "Error fetching: " + e.getMessage());
                             }
                       }


                 });
                }
    }//for loop
            });


        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 {

                }
                }
            });

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

            public void done(List<ParseUser> userlistname, ParseException e) {
                if (e == null) {
                    for (int i = 0; i < userlistname.size(); i++) {
                        names.add(userlistname.get(i).get("Name").toString());
                    }
                    usersListName = (ListView) getActivity().findViewById(
                            R.id.userlistname);
                    namesArrayAdapter = new ArrayAdapter<String>(getActivity()
                            .getApplicationContext(), R.layout.user_list_name,
                            names);
                    usersListName.setAdapter(namesArrayAdapter);


                } else {

                }
                }
            });


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

            public void done(List<ParseUser> userlistheadline, ParseException e) {
                if (e == null) {
                    for (int i = 0; i < userlistheadline.size(); i++) {
                        headline.add(userlistheadline.get(i).get("Headline")
                                .toString());
                    }
                    usersListHeadline = (ListView) getActivity().findViewById(
                            R.id.userlistheadline);
                    namesArrayAdapter = new ArrayAdapter<String>(getActivity()
                            .getApplicationContext(), R.layout.user_list_all,
                            headline);
                    usersListHeadline.setAdapter(namesArrayAdapter);



                } else {

                }
            }
        });

    }

    public void openConversation(ArrayList<String> names, int pos) {
        ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.whereEqualTo("Name", names.get(pos));
        query.findInBackground(new FindCallback<ParseUser>() {
            public void done(List<ParseUser> user, ParseException e) {
                if (e == null) {
                    Intent intent = new Intent(getActivity()
                            .getApplicationContext(), MessagingActivity.class);
                    intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
                    startActivity(intent);
                } else {
                    Toast.makeText(getActivity().getApplicationContext(),
                            "Error finding that user", Toast.LENGTH_SHORT)
                            .show();
                }
            }
        });
    }

}

如果您需要其他信息,请与我们联系。

2 个答案:

答案 0 :(得分:0)

我不确定我是否理解你的问题。 您是否尝试过以这种方式设置TextView文本?

text.setText("ActivityName");

答案 1 :(得分:0)

那样的东西?

text.setText(userlistactivityname.get(0).get("ActivityName"))