我有一个带有scrollview
. 在里面,我有一个LinearLayout
and Button
。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:scrollbars="none">
<LinearLayout
android:id="@+id/ll_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
android:padding="10dp">
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="OK" />
</LinearLayout>
我正在使用 a dialogfragment
查看此布局。我也在尝试textview
动态添加一个。下面是我的课
public class SecondLevelAdapter extends BaseExpandableListAdapter {
private void showPreFilledData(String string) {
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.cust_data_layout);
dialog.setTitle("Customer Info");
final LinearLayout linearLayout = new LinearLayout(context);
linearLayout.findViewById(R.id.ll_details);
TextView textView1 = new TextView(context);
textView1.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
textView1.setGravity(Gravity.CENTER);
textView1.setText("programmatically created TextView1");
linearLayout.addView(textView1);
Button ok;
ok = (Button) dialog.findViewById(R.id.ok);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
Window window = dialog.getWindow();
window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT);
dialog.show();
}
}
但是当我启动应用程序时,我无法看到textview
.
我一定错过了一些我不知道的东西。
任何帮助将不胜感激。