我在这方面花了太多时间。最初,我使用一个简单的"onAction"方法与XML onclick语句并行来控制位于ExpandableListView中的一个按钮。我认为使用通货膨胀会很好,这样我就可以在运行时更好地控制按钮。你可以在这里看到更早的帖子
这是我最近的一次尝试。我没有得到任何异常或错误,只是什么都没做。我知道这个版本有点牵强,所以如果你有时间,在建议我可能已经尝试过的东西之前,请查看上面的链接,了解我的其他尝试!
BrowseActivity.class
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browse);
ViewGroup parent = (ViewGroup) findViewById(R.id.expandLinLayout);
ExpandableListView browseView = (ExpandableListView) findViewById(android.R.id.list);
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.row, parent);
LinearLayout linLay = (LinearLayout) view
.findViewById(R.id.LinearLayout1);
TextView rowTxt = (TextView) view.findViewById(R.id.txtItem);
rowTxt.setTextColor(Color.CYAN);
.........
}
browse.xml包含以下列表的代码:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"
android:id="@+id/expandLinLayout"
>
<ExpandableListView
android:id = "@android:id/list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:groupIndicator="@drawable/my_group_statelist"
>
</ExpandableListView>
</LinearLayout>
最后是row.xml代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_gravity="center_vertical|right"
android:id="@+id/txtItem"
android:text="Item"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
></TextView>
</LinearLayout>
如有任何帮助或建议,我们将不胜感激。
尝试初始化布局充气机
LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);