私はアンドロイドのUIデザインに慣れ親しむ簡単なプログラムを書いています。私は線形レイアウト内にテキストを動的に追加しました。私がコードをデバッグすると、私はlogcatのエラーを見ることができません、コードは完璧に実行されます。しかし、私は自分のデバイス内のテキストを見ることができません。私はギャラクシーS2を使用しています。私はエミュレータも使用しようとしました。しかし何も現れなかった。デバイス/エミュレータにテキストが表示されない理由がわかりません。助けてください。ここで androidのlinearlayout内でtextviewを見ることができません
は、ここに私のmain.xmlがある私の活動public class ViewActivity extends Activity {
/** Called when the activity is first created. */
LinearLayout bar;
String myarray[]={"Foot Ball","Basket Ball","Cricket"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bar= (LinearLayout) findViewById(R.id.tag);// Map the Layout
bar.setVisibility(View.VISIBLE);
TextView bs_text[]= new TextView[myarray.length]; // Create TextView according to value in length variable;
for(int z=0;z< myarray.length ;z++)
{
try
{
bs_text[z] = (TextView) new TextView(this);
bs_text[z].setText(myarray [z]);
//bs_text[z].setTextSize(1);
bs_text[z].setBackgroundColor(android.graphics.Color.TRANSPARENT);
bs_text[z].setTextColor(android.graphics.Color.BLACK);
int height_in_pixels = bs_text[z].getLineCount() * bs_text[z].getLineHeight(); //approx height text
bs_text[z].setHeight(height_in_pixels);
//bs_text[z].setHeight(android.graphics.)
bar.addView(bs_text[z]);
}
catch(ArrayIndexOutOfBoundsException e)
{
Log.d("ArrayIndexOutOfBoundsException",e.toString());
}
}
}
}
ある
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tag"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</LinearLayout>
こんにちはmithu、このコードを試してみましょう。 –