在选择AutoCompleteTextView的元素时,我无法添加文本视图。你能在这段代码中找到问题吗?
actv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView tv = new TextView(view.getContext());
tv.setText("something");
Log.d("Test","Test");//Works!!
layout=(LinearLayout) findViewById(R.id.container);
layout.addView(tv);
}
});
这是我的活动布局:
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/global">
<LinearLayout
android:orientation="vertical"
android:layout_width="382dp"
android:layout_height="518dp"
android:id="@+id/container"
android:focusableInTouchMode="false">
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView_aff_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/cli_id"
android:hint="Choisissez un prospect"
android:ems="10"
android:text="">
</AutoCompleteTextView>
</LinearLayout>
答案 0 :(得分:0)
您没有为TextView
设置任何布局参数,所以基本上您没有告诉它应该如何显示。尝试这样的事情:
final TextView tv = new TextView(this);
tv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
...
layout.addView(tv);