Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically display imagebuttons in AsyncTask
    primarykey
    data
    text
    <p>So I am retrieving images from Parse and dynamically displaying them in a ScrollView LinearLayout, but I can't seem to add a clickListener or add them to the view. Here's what I have:</p> <pre><code>MyTaskParams params = new MyTaskParams(drinkList.get(j).getString("Name"), data, lPos, drinkList.get(j).getObjectId(), j); MyTask myTask = new MyTask(); myTask.execute(params); </code></pre> <p>And then in I pass all my data and try adding the ImageButton to the view.</p> <pre><code>private static class MyTaskParams { String name; byte[] data; int lPos; String id; int j; public MyTaskParams(String name, byte[] data, int lPos, String id, int j) { this.data = data; this.name = name; this.lPos = lPos; this.id = id; this.j = j; } } private class MyTask extends AsyncTask&lt;MyTaskParams, Void, MyTaskParams&gt; { @Override protected MyTaskParams doInBackground(MyTaskParams... params) { String name = params[0].name; byte[] data = params[0].data; int lPos = params[0].lPos; String id = params[0].id; int j = params[0].j; Log.d("DOINBACKGROUND", data.toString()); bmp = BitmapFactory.decodeByteArray(data, 0, data.length); btn = new ImageButton(getActivity()); btn.setId(j); btn.setTag(name); btn.setImageBitmap(bmp); btn.setBackgroundDrawable(null); btn.setMaxHeight(100); btn.setMaxWidth(100); btn.setOnClickListener(new DrinkButtonListener(getActivity(), lPos, id)); lLayout[lPos].addView(btn); return null; } } </code></pre> <p>Why can't I create a ClickListener or add the button to the view? I get the error:</p> <p>"Only the original thread that created a view hierarchy can touch its views" </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload