我是Android新手,我正在尝试以编程方式将TableRow(我已经用xml创建)添加到TableLayout.我得到Force Closes,大多数都是NullPointerExcpetions.
这是我的java类
public class DayFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.subjects_list, container, false);
TableLayout tl = (TableLayout) view.findViewById(R.id.tl);
TableRow tr = (TableRow) view.findViewById(R.id.tr_row);
tl.addView(tr); //not working, obviously im missing something
//xml parsing stuff
return view;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我使用TableLayout的布局:
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="5dp" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical" >
<TableLayout
android:id="@+id/tl"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<include
android:id="@+id/header"
layout="@layout/table_header" />
<include android:id="@+id/h_divider"
layout="@layout/horizontal_divider"/>
</TableLayout>
</ScrollView> …Run Code Online (Sandbox Code Playgroud) 我一直试图将ActionBar徽标或"向上"按钮设为文本而不是图像.actionbar.setLogo();仅接受可绘制资源.使用a充气布局TextView没有做到这一点.
基本上,我想要完成的是:

第一个来自Android 4.2的新DeskClock应用程序,第二个来自Contacts应用程序.我检查了GitHub中的代码,但我找不到任何东西.