質問

My code for adding a view is :

LL = (LinearLayout) findViewById(R.id.LL);
LL.removeAllViewsInLayout(); //Works fine, is necessary for a separate reason
tx = new TextView(this);
tx.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
LL.addView(tx); //Program fails

The program stops at the addView function.

役に立ちましたか?

解決

I found my mistake. I was calling the the above function(of MainActivity) through an AsyncTask class(by a listener) and rather than calling in OnPostExecute I was calling at end of doInBackground.

他のヒント

"tx" is not an array, so you can't access tx[i]. You want LL.addView(tx);

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top