我在这上面花了太多时间。最初,我使用简单的“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>
任何帮助或建议将不胜感激。