Android动态布局仅在oncreate方法完成后显示 isAnswered=0; @凌驾 创建时受保护的void(Bundle savedInstanceState){ 日志d(标签“1无应答:+无应答”); Log.d(标记为“matchinggame OnCreate”); super.onCreate(savedInstanceState); dbHandler=新的DatabaseHandler(此); rLayout=新的RelativeLayout(本); object=新的ObjectObject(); imageAnswer=新的ImageView(本); setContentView(rLayout); trainingID=getIntent().getExtras().getInt(“trainingID”); trainingObjectList=new ArrayList(); trainingObjectList=dbHandler.getAllTrainingObject(trainingID); ////TODO:2016年5月2日egitim kismi oalcak burda tek tek gosterilecek rLayout.setBackgroundColor(颜色为洋红色); //Handler Handler=new Handler();Log.d(标记“2isanswered:+isAnswered”); 对于(int i=0;i
发生这种情况是因为在Android动态布局仅在oncreate方法完成后显示 isAnswered=0; @凌驾 创建时受保护的void(Bundle savedInstanceState){ 日志d(标签“1无应答:+无应答”); Log.d(标记为“matchinggame OnCreate”); super.onCreate(savedInstanceState); dbHandler=新的DatabaseHandler(此); rLayout=新的RelativeLayout(本); object=新的ObjectObject(); imageAnswer=新的ImageView(本); setContentView(rLayout); trainingID=getIntent().getExtras().getInt(“trainingID”); trainingObjectList=new ArrayList(); trainingObjectList=dbHandler.getAllTrainingObject(trainingID); ////TODO:2016年5月2日egitim kismi oalcak burda tek tek gosterilecek rLayout.setBackgroundColor(颜色为洋红色); //Handler Handler=new Handler();Log.d(标记“2isanswered:+isAnswered”); 对于(int i=0;i,android,sqlite,android-layout,Android,Sqlite,Android Layout,发生这种情况是因为在onCreate方法完成之前没有显示活动。请尝试将代码移动到onResume并查看它是否有效。另外,在当前代码中,不要忘了调用super.onCreate(savedInstanceState)相同:(我将for循环后的代码恢复到onresume,但不起作用。因此,如果oncreate必须完成更新布局,我该怎么做?因为for循环中有5次迭代,每次迭代都有不同的布局,我建议使用AsyncTask并更新布局onPostExecuted。您可以在此处进一步阅读,但我无法在此处同步。
onCreate
方法完成之前没有显示活动。请尝试将代码移动到onResume
并查看它是否有效。另外,在当前代码中,不要忘了调用super.onCreate(savedInstanceState)
相同:(我将for循环后的代码恢复到onresume,但不起作用。因此,如果oncreate必须完成更新布局,我该怎么做?因为for循环中有5次迭代,每次迭代都有不同的布局,我建议使用AsyncTask
并更新布局onPostExecuted
。您可以在此处进一步阅读,但我无法在此处同步。)n drag是真的,gooher迭代?
isAnswered=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG,"1isanswered : "+isAnswered);
Log.d(TAG, "matchinggame OnCreate");
super.onCreate(savedInstanceState);
dbHandler = new DatabaseHandler(this);
rLayout = new RelativeLayout(this);
object = new ObjectObject();
imageAnswer=new ImageView(this);
setContentView(rLayout);
trainingID = getIntent().getExtras().getInt("trainingid");
trainingObjectList = new ArrayList<TrainingObject>();
trainingObjectList = dbHandler.getAllTrainingObject(trainingID);
//// TODO: 02.05.2016 egitim kismi oalcak burda tek tek gosterilecek
rLayout.setBackgroundColor(Color.MAGENTA);
// Handler handler = new Handler(); Log.d(TAG,"2isanswered : "+isAnswered);
for(int i=0;i<2;i++){Log.d(TAG,"i:"+i); Log.d(TAG,"3tisanswered : "+isAnswered);
final int finalI = i;
// handler.postDelayed(new Runnable() {
// @Override
// public void run() {Log.d(TAG,"thread i: "+finalI);
Log.d(TAG,"4isanswered : "+isAnswered);
isAnswered = 0;
TrainingObject trainingObject = new TrainingObject();
trainingObject = trainingObjectList.get(finalI);
objectCount = 2;
//test icin
Log.d(TAG,"testicin trainingobjectid: "+trainingObject.getTrainingobjectID());
object = dbHandler.getObjectObject(trainingObject.getTrainingobjectAnswer());
if(trainingObject.getTrainingobjectThree()!=0) objectCount++;
if(trainingObject.getTrainingobjectFour()!=0) objectCount++;
if(trainingObject.getTrainingobjectFive()!=0) objectCount++;
Log.d(TAG,"matchinggame objcount: "+objectCount);
RelativeLayout.LayoutParams rLayParams = new RelativeLayout.LayoutParams(140,140);
rLayParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
rLayParams.addRule(RelativeLayout.CENTER_IN_PARENT);
imgBytes = object.getObjectImageBlob();
bmp = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
imageAnswer.setImageBitmap(bmp);
imageAnswer.setTag(trainingObject.getTrainingobjectAnswer());
imageAnswer.setId(R.id.imgAnswer);
rLayout.removeAllViews();
rLayout.addView(imageAnswer,rLayParams);
imageOne.setOnDragListener(MatchingGame.this);
imageAnswer.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) { Log.d(TAG,"6isanswered : "+isAnswered);
Log.d(TAG,"matchinggame setontouch");
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Log.d(TAG,"matchinggame setontouch if yes");
ClipData data = ClipData.newPlainText("", "");
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
v.startDrag(data, shadowBuilder, v, 0);
v.setVisibility(View.INVISIBLE); Log.d(TAG,"7isanswered : "+isAnswered);
return true;
} else { Log.d(TAG,"8isanswered : "+isAnswered);
return false;
}
}
});
imageAnswer.setOnDragListener(MatchingGame.this);
Log.d(TAG,"*");
while(isAnswered==0){
//Log.d(TAG,"*");
}
// }
// }, 30000*finalI );Log.d(TAG,"thread sonrasi: "+finalI); Log.d(TAG,"5isanswered : "+isAnswered);
}Log.d(TAG,"ff");
}