I'm using thread (runOnUiThread) for adding imageView to mainActivity.
i don't know what should i import to constructor! It want context and i tried MainActivity.this
and getApplicationContext()
and getBaseContext()
but it doesn't work!
public void addImageView(final int belowId,final int id){
runOnUiThread(new Runnable() {
@Override
public void run() {
RelativeLayout rSub= (RelativeLayout) findViewById(R.id.rSub);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.BELOW, belowId);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
ImageView iv = new ImageView(?????);
iv.setImageResource(R.drawable.ic_launcher);
iv.setId(id);
rSub.addView(iv, lp);
}
});
}
and call it :
new Thread(new Runnable() {
@Override
public void run() {
addImageView(belowId, tempId);
}
}).start();
any help appreciated!