我让他们选择可扩展的孩子列表并获取信息。我还想为每个孩子实现一个数字选择器。但问题是孩子们不会选择,我也无法访问数字选择器按钮。我不使用任何侦听器,也不使用充气机访问 xml。不知道还能做什么。感谢所有的帮助。
代码主类
final ControlClientMenu adapt = new ControlClientMenu(ClientMenu.this, detalls);
lstComandes = (ExpandableListView) findViewById(R.id.lstComandes); //Creo la lista
lstComandes.setLongClickable(true);
lstComandes.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
parent.expandGroup(groupPosition);
parent.collapseGroup(groupPosition);
return false;
}
});
lstComandes.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
id_comanda = id.get(arg2);
return false;
}
});
lstComandes.setAdapter(adapt); //Le asigano el XML
registerForContextMenu(lstComandes);
代码扩展适配器
public class ControlClientMenu extends BaseExpandableListAdapter
{
Context context;
DetallsComandes[] detalls;
private ArrayList<String> grupos = new ArrayList<String>();
private ArrayList<ArrayList<ArrayList<String>>> hijos = new ArrayList<ArrayList<ArrayList<String>>>();
private ArrayList<ArrayList<ArrayList<String>>> hijosU = new ArrayList<ArrayList<ArrayList<String>>>();
public ControlClientMenu(Context context, DetallsComandes[] detalls)
{
this.context = context;
this.detalls = detalls;
cargarDatos();
}
public void cargarDatos() //Funcion para separar los grupos de los hijos
{
for(int i = 0; i<detalls.length;i++)
{
Log.d("De", detalls[i].getComanda());
grupos.add(detalls[i].getComanda());
hijos.add(new ArrayList<ArrayList<String>>());
hijosU.add(new ArrayList<ArrayList<String>>());
Vector aux = detalls[i].getVecProducte();
Vector aux2 = detalls[i].getVecPreu();
Vector aux3 = detalls[i].getVecUnitats();
for(int j = 0; j<aux.size(); j++)
{
Log.d("CONT", aux.get(j).toString()+" "+aux2.get(j).toString());
hijos.get(i).add(new ArrayList<String>());
hijosU.get(i).add(new ArrayList<String>());
hijos.get(i).get(j).add(aux.get(j).toString()+" "+aux2.get(j).toString());
hijosU.get(i).get(j).add(aux3.get(j).toString());
}
}
}
public ArrayList<String> getChild(int groupPosition, int childPosition)
{
return hijos.get(groupPosition).get(childPosition);
}
public ArrayList<String> getChild1(int groupPosition, int childPosition, ArrayList<ArrayList<ArrayList<String>>> hijosU)
{
return hijosU.get(groupPosition).get(childPosition);
}
public long getChildId(int groupPosition, int childPosition)
{
return childPosition;
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
String hijo = (String) ((ArrayList<String>)getChild(groupPosition, childPosition)).get(0);
String hijo2 = (String) ((ArrayList<String>)getChild1(groupPosition, childPosition, hijosU)).get(0);
if (convertView == null)
{
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.tabla_comanda_product_item, null);
}
TextView hijotxt = (TextView) convertView.findViewById(R.id.item_prod);
TextView hijoU = (TextView) convertView.findViewById(R.id.txtUnitats);
hijotxt.setText(hijo);
hijoU.setText(hijo2);
return convertView;
}
public int getChildrenCount(int groupPosition)
{
return hijos.get(groupPosition).size();
}
public String getGroup(int groupPosition)
{
return grupos.get(groupPosition);
}
public int getGroupCount()
{
return grupos.size();
}
public long getGroupId(int groupPosition)
{
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
{
String group = (String)getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.tabla_comanda, null);
}
TextView grouptxt = (TextView) convertView.findViewById(R.id.lblComanda);
grouptxt.setText(group);
return convertView;
}
public boolean hasStableIds()
{
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition)
{
return true;
}
}
主要 XML
<TabHost
android:id="@android:id/tabhost"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ExpandableListView android:id="@+id/lstComandes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10px"
android:paddingTop="5px">
</ExpandableListView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
可扩展组 XML
<?xml version="1.0" encoding="utf-8"?>
<!--VISTA DE LA EXPANDIBLELIST-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<!--CODIGO Y NOMBRE DEL CLIENTE-->
<TextView android:id="@+id/lblComanda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:textSize="11dp"
android:layout_marginLeft="53px"
android:gravity="center_vertical"
android:paddingTop="15px"
android:paddingBottom="15px"/>
</LinearLayout>
<!-- <ListView android:id="@+id/lstProd" -->
<!-- android:layout_width="fill_parent" -->
<!-- android:layout_height="wrap_content" /> -->
<!-- <TextView android:id="@+id/lblTabla2" -->
<!-- android:layout_width="wrap_content" -->
<!-- android:layout_height="wrap_content"/> -->
</LinearLayout>
可扩展子 XML
<?xml version="1.0" encoding="utf-8"?>
<!-- VISTA DE LOS SUBLISTA DE LA EXPANDIBLE LIST -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingTop="13px"
android:paddingBottom="15px"
android:paddingLeft="20px">
<!--PRODUCTO PRECIO SUBTOTAL-->
<TextView android:id="@+id/item_prod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"/>
<!-- NUMBERPICKER -->
<LinearLayout android:gravity="right"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button android:id="@+id/btnDown"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="@string/down"/>
<TextView android:id="@+id/txtUnitats"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<Button android:id="@+id/btnUp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="@string/up"/>
</LinearLayout>
</LinearLayout>
对不起我的西班牙代码。