vendredi 24 avril 2015

Unboxing Integer[] in AsyncTask

I am trying to populate several TextViews with data from AWS using an AsyncTask. In order to the load the data from AWS, I must submit a range-key value which is an int. AsyncTask will only allow you to send Integers as parameters.

Problem: How can I unbox the Integer parameters as int so that I can send the primitive int to AWS (during doInBackground) and grab the data?

(slots is the variable which identifies the data i want to grab for the view)

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

    class LoadPost extends AsyncTask<Integer, Void, Post> {
        @Override
        protected Post doInBackground(Integer... slots) {

            int i = (int) slots; <=this does not work

            Post post = AmazonCredentials.getInstance().mapper.load(Post.class, userID, slots);
            return post;
        }
        protected void onPostExecute(Post post) {
            int slotNumber = post.getSlotNumber();

            int resID = getResources().getIdentifier("slot"+slotNumber, "id", "package name goes here");

            TextView slot = (TextView) view.findViewById(resID);
            slot.setText(post.getContent());
        }
    }




Aucun commentaire:

Enregistrer un commentaire