- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想显示一棵树,该树具有其父节点、第二个节点及其子节点的单独名称。我已经使用 Google 帮助进行了编码。该代码显示树具有所有具有相同名称的第二个和子节点。如何为树的每个节点指定唯一的名称?
我的Java代码是:
package com.example.tree;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;
public class MainActivity extends Activity {
ExpandableListView explvlist;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
explvlist = (ExpandableListView)findViewById(R.id.ParentLevel);
explvlist.setAdapter(new ParentLevel());
}
public class ParentLevel extends BaseExpandableListAdapter
{
@Override
public Object getChild(int arg0, int arg1)
{
return arg1;
}
@Override
public long getChildId(int groupPosition, int childPosition)
{
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{
CustExpListview SecondLevelexplv = new CustExpListview(MainActivity.this);
SecondLevelexplv.setAdapter(new SecondLevelAdapter());
SecondLevelexplv.setGroupIndicator(null);
return SecondLevelexplv;
}
@Override
public int getChildrenCount(int groupPosition)
{
return 4;
}
@Override
public Object getGroup(int groupPosition)
{
return groupPosition;
}
@Override
public int getGroupCount()
{
return 1;
}
@Override
public long getGroupId(int groupPosition)
{
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent)
{
TextView tv = new TextView(MainActivity.this);
tv.setText("Unit Testing");
tv.setBackgroundColor(Color.BLUE);
tv.setPadding(10, 7, 7, 7);
return tv;
}
@Override
public boolean hasStableIds()
{
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition)
{
return true;
}
}
public class CustExpListview extends ExpandableListView
{
int intGroupPosition, intChildPosition, intGroupid;
public CustExpListview(Context context)
{
super(context);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
widthMeasureSpec = MeasureSpec.makeMeasureSpec(960, MeasureSpec.AT_MOST);
heightMeasureSpec = MeasureSpec.makeMeasureSpec(600, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public class SecondLevelAdapter extends BaseExpandableListAdapter
{
@Override
public Object getChild(int groupPosition, int childPosition)
{
return childPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition)
{
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{
TextView tv = new TextView(MainActivity.this);
tv.setText("Campaign Page should not be null");
tv.setPadding(15, 5, 5, 5);
tv.setBackgroundColor(Color.RED);
tv.setLayoutParams(new ListView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
return tv;
}
@Override
public int getChildrenCount(int groupPosition)
{
return 2;
}
@Override
public Object getGroup(int groupPosition)
{
return groupPosition;
}
@Override
public int getGroupCount()
{
return 1;
}
@Override
public long getGroupId(int groupPosition)
{
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent)
{
TextView tv = new TextView(MainActivity.this);
tv.setText("Get Campaign");
tv.setPadding(12, 7, 7, 7);
tv.setBackgroundColor(Color.CYAN);
return tv;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}
}
我希望树的每个第二个节点和子节点都有唯一的名称和不同的颜色。
最佳答案
表示您想要根据父名称查看数据树。?所以你使用了可扩展 ListView 。?对吧..?
使用这些代码..
main.xml 具有
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardCodedText" >
<ExpandableListView
android:id="@+id/expandableListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dip"
android:groupIndicator="@null"
android:scrollbars="none" >
</ExpandableListView>
</RelativeLayout>
并创建一个 ExpandListGroup.java 文件并添加这些代码
public class ExpandListGroup {
private String Name;
private ArrayList<ExpandListChild> Items;
public ExpandListGroup(String name, ArrayList<ExpandListChild> items) {
super();
Name = name;
Items = items;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public ArrayList<ExpandListChild> getItems() {
return Items;
}
public void setItems(ArrayList<ExpandListChild> items) {
Items = items;
}
}
为子级添加另一个 ExpandListChild.java 文件
public class ExpandListChild {
private String Name;
private String Tag;
public ExpandListChild(String name, String tag) {
super();
Name = name;
Tag = tag;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getTag() {
return Tag;
}
public void setTag(String tag) {
Tag = tag;
}
}
并将这些代码添加到您的 MainActivity.java
public class ConfigureMyOrderItem extends MainActivity {
private ArrayList<ExpandableConfigureGroup> group_list;
private ArrayList<ExpandableConfigureChild> child_list;
ExpandableListView mExpandableListView;
ConfigureMyOrderAdapter adapter;
Button btn_confirm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_configure_my_order_item);
initView();
}
public void initView() {
mExpandableListView = (ExpandableListView) findViewById(R.id.expandableListViewConfigure);
btn_confirm = (Button) findViewById(R.id.btn_Confirm_order);
btn_confirm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ConfigureMyOrderItem.this,
MyOrderActivity.class);
startActivity(intent);
}
});
group_list = SetStandardGroups();
adapter = new ConfigureMyOrderAdapter(ConfigureMyOrderItem.this,
mExpandableListView, group_list);
mExpandableListView.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater()
.inflate(R.menu.activity_configure_my_order_item, menu);
return true;
}
public ArrayList<ExpandableConfigureGroup> SetStandardGroups() {
group_list = new ArrayList<ExpandableConfigureGroup>();
child_list = new ArrayList<ExpandableConfigureChild>();
group_list.add(new ExpandableConfigureGroup("Group", child_list));
child_list.add(new ExpandableConfigureChild("Child1"));
child_list.add(new ExpandableConfigureChild("Child2"));
child_list.add(new ExpandableConfigureChild("Child3"));
child_list.add(new ExpandableConfigureChild("Child4"));
child_list = new ArrayList<ExpandableConfigureChild>();
group_list.add(new ExpandableConfigureGroup("Category",
child_list));
child_list.add(new ExpandableConfigureChild("Item1"));
child_list.add(new ExpandableConfigureChild("Item2"));
child_list.add(new ExpandableConfigureChild("Item3"));
child_list.add(new ExpandableConfigureChild("Item4"));
}
public void HomeButton(View v) {
startActivity(new Intent(v.getContext(), MainActivity.class));
}
@Override
public void onClickQuickView(View v) {
// TODO Auto-generated method stub
super.onClickQuickView(v);
}
@Override
public void onClickQuickViewStatus(View v) {
// TODO Auto-generated method stub
super.onClickQuickViewStatus(v);
}
}
同时创建ConfigureMyOrderAdapter.java 文件
public class ConfigureMyOrderAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<ExpandableConfigureGroup> groups;
private ExpandableListView mExpandableListView;
private int[] groupStatus;
public ConfigureMyOrderAdapter(Context context,
ExpandableListView mExpandableListView,
ArrayList<ExpandableConfigureGroup> groups) {
this.context = context;
this.groups = groups;
this.mExpandableListView = mExpandableListView;
groupStatus = new int[groups.size()];
setListEvent();
}
private void setListEvent() {
mExpandableListView
.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int arg0) {
// TODO Auto-generated method stub
groupStatus[arg0] = 1;
}
});
mExpandableListView
.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int arg0) {
// TODO Auto-generated method stub
groupStatus[arg0] = 0;
}
});
}
public void addItem(ExpandableConfigureChild item,
ExpandableConfigureGroup group) {
if (!groups.contains(group)) {
groups.add(group);
}
int index = groups.indexOf(group);
ArrayList<ExpandableConfigureChild> ch = groups.get(index).getItems();
ch.add(item);
groups.get(index).setItems(ch);
}
public Object getChild(int groupPosition, int childPosition) {
ArrayList<ExpandableConfigureChild> chList = groups.get(groupPosition)
.getItems();
return chList.get(childPosition);
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean arg2, View view, ViewGroup arg4) {
ExpandableConfigureChild child = (ExpandableConfigureChild) getChild(
groupPosition, childPosition);
if (view == null) {
@SuppressWarnings("static-access")
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(
R.layout.configure_list_raw_group_item, null);
}
TextView tv_price = (TextView) view.findViewById(R.id.item_price);
tv_price.setText(child.getTag().toString());
tv_price.setTag(child.getTag());
return view;
}
@Override
public int getChildrenCount(int groupPosition) {
ArrayList<ExpandableConfigureChild> chList = groups.get(groupPosition)
.getItems();
return chList.size();
}
@Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
@Override
public int getGroupCount() {
return groups.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@SuppressWarnings("static-access")
@Override
public View getGroupView(int groupPosition, boolean arg1, View view,
ViewGroup arg3) {
ExpandableConfigureGroup group = (ExpandableConfigureGroup) getGroup(groupPosition);
if (view == null) {
LayoutInflater inf = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = inf.inflate(R.layout.configure_list_raw_group, null);
}
TextView tv = (TextView) view.findViewById(R.id.txtRestaurantMenuName);
tv.setText(group.getName());
ImageView img = (ImageView) view.findViewById(R.id.img_rightarrow);
if (groupStatus[groupPosition] == 0) {
img.setImageResource(R.drawable.navigation_next);
} else {
img.setImageResource(R.drawable.navigation_expandable);
}
return view;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int arg0, int arg1) {
return true;
}
}
并且还为自定义configure_list_raw_group.xml 布局创建两个xml。原来如此
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="45dip"
android:orientation="horizontal"
android:weightSum="100"
tools:ignore="HardCodedText" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="45dip"
android:layout_marginLeft="4dip"
android:layout_weight="88"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="@+id/txtRestaurantMenuName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RestaurantMenu Name"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:id="@+id/img_rightarrow"
android:layout_width="0dip"
android:layout_height="45dip"
android:layout_gravity="center_vertical"
android:layout_weight="7"
android:contentDescription="@string/hello_world"
android:src="@drawable/navigation_next_item" />
</LinearLayout>
第二个是configure_list_raw_group_item.xml组的子组。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/groupItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="horizontal"
android:weightSum="100"
tools:ignore="HardCodedText" >
<TextView
android:id="@+id/item_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_weight="75"
android:text="sample"
android:textSize="12sp" />
</LinearLayout>
关于java - 如何为每个节点指定唯一的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15401715/
我正在我的 java 作业中使用 GUI,并且我必须指定 JCheckBox 中的其他内容。除了这个小要求,其他的我都完成了。我不太确定如何解决这个问题,我查阅了我的书并尝试在线研究 要求: 一系列复
在各种语言中(我将在这里使用 JavaScript,但我已经在 PHP 和 C++ 中以及可能在其他地方看到过它),似乎有几种构造简单 for 循环的方法。版本 1 如下: var top = doc
有没有一种方法可以使用 CSS 指定每次“小于符号”(在键盘上 M 的右侧)或“大于符号”出现在文本中时,它应该被替换为分别是“小于”或“大于”的实际词? 最佳答案 CSS 不能作用于(不能修改,即)
首先,使用 setspn 命令为用户注册服务主体名称。 setspn -a CS/dummy@abc.com dummyuser setspn -l dummyuser 给出输出为 CS/dummy@
我在指定从 SFSafariViewController 访问时遇到问题,因为它具有与 Safari 浏览器完全相同的用户代理。 我要做的是仅在 webview 内显示图片,如果在普通浏览器上查看,则
我正在尝试用 R 语言在 lavaan 中指定一个奇怪的模型。该模型如下所示: 我的规范尝试如下所示。我发现难以实现的是将观察到的变量的唯一误差固定为唯一项的两个相关性的总和。 例如,项目 y*1,2
我正在构建 API 以将我的 React 应用程序与我的后端服务连接起来,我想使用 typescript 来指定 data 的类型在我的 Axios 请求中。如何在不修改其他字段的情况下更新 Axio
如何为模型指定初始“软”值?该初始模型是解决类似查询的结果,并且该模型很可能具有正确的部分,甚至对于当前查询可能是正确的。 目前,我正在通过增量求解和 hard/soft constraints 对此
我有来自网页的以下代码 https://cwiki.apache.org/confluence/display/KAFKA/0.8.0+Producer+Example 似乎缺少的是如何配置分区数。我
有没有办法在每个查询的基础上在 Neo4jClient 中指定 Cypher 解析器的版本,如 here 所述? 谢谢! 最佳答案 如果您将 Neo4jClient 更新到最新版本(> 1.0.0.6
我有以下代码生成四个图,但它们最终被压扁(见下图)。我该如何解决这个问题? par(mfrow=c(2,2)) curve(.5*exp(-.5*x),from=0,to=10,main="f(x)"
我有一个 ColdFusion 10 服务器。我正在使用 JDBC 驱动程序连接到 db2 数据库。我偶然发现了这个笔记。这个设置在哪里?我还查看了 neo*.xml 文件,但没有看到任何 db 驱动
我想知道是否可以指定验证器的运行顺序。 目前,我编写了一个自定义验证器,检查它是否为 [a-zA-Z0-9]+ 以确保登录验证我们的规则,并编写了一个远程验证器以确保登录可用,但目前远程验证器已启动在
我的应用程序需要至少 40MB 的 RAM,因此早期的 iPhone(例如 3G、第一个 iPod touch 版本)就没有它(它们为我的应用程序提供的最大内存约为 20MB)。有没有正确的方法来禁用
我有一个保存日期(不是当前日期)的 Date 对象,我需要以某种方式指定该日期为 UTC,然后将其转换为“欧洲/巴黎”,即 +1 小时。 public static LocalDateTime toL
我想问你在 Varnish 代码中如何在没有缓存的情况下将请求传递到后端。 我知道我可以做到并且正在发挥作用: if (req.url ~ "(\?|&)(something|somethin
我目前基于模块编译程序(如主程序 foo 依赖于模块 bar )如下: gfortran -c bar.f90 gfortran -o foo.exe foo.f90 bar.o 这在 foo.f90
我正在尝试创建一个依赖于另一个 meteor 包的新 meteor 包。当我尝试 meteor add mypackage 时,出现以下错误。为什么 Meteor 不添加 mypackage 并引入它
我正在制作执行器/ react 器,同时发现这是一个终生的问题。它与 async/Future 无关,可以在没有 async 糖的情况下进行复制。 use std::future::Future; s
我在 cassandra 中有一个表,其数据类型为时间戳。我正在使用 cqlsh 从数据库中获取数据,并希望更改我的时间戳列输出的输出格式。我研究了一下,发现我可以通过更改以下文件来更改时间戳输出格式
我是一名优秀的程序员,十分优秀!