vipy123 2014-02-19 09:59
浏览 1771

Expandlelistview动态更新

每个child的嵌套了一个tableLayout,我现在点一下edittext 就获得系统时间,点下提交按钮,然后数据存起来。我想请问下我改怎么获取每个edittext的值,怎么用set方法,怎么存入链表

package com.example.expandablelisttest;

import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.os.Bundle;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.util.Log;
import android.view.Menu;
import android.widget.ExpandableListView;
import android.widget.TimePicker;
import android.widget.Toast;

public class MainActivity extends Activity {

private static MainActivity mainActivity = null;
final static int SHOW_DIALOG = 1;
static int id=1;
int hour, minute;
EditTextClick e=new EditTextClick();

server s = new server();
server1 s1 = new server1();
final private ArrayList<String> groups = new ArrayList<String>();
final private ArrayList<ArrayList<T>> childs = new ArrayList<ArrayList<T>>();
GetGroupValueFromServer group = new GetGroupValueFromServer(s.getValue());
GetChildValueFromServer child = new GetChildValueFromServer(s1.getValue());



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mainActivity=this;

    for (int i = 0; i <= group.getTotalGroupCount() - 1; i++) {
        groups.add(group.getEachGroupValue(i));
    }

    ArrayList<T> childValue = new ArrayList<T>();
    for (int i = 0; i <= child.getTotalChildCount() - 1; i++) {

        childValue.add(child.getEachChildValue(i));
        childs.add(childValue);
    }

    PreExpandableListAdapter adapter = new PreExpandableListAdapter(groups,
            childs, this);

    ExpandableListView expandListView = (ExpandableListView) findViewById(R.id.list);

    expandListView.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.main, menu);
    return true;
}

}

public class PreExpandableListAdapter extends BaseExpandableListAdapter {

private List<String> group;
private List<ArrayList<T>> children;
private Context context;

public PreExpandableListAdapter(List<String> group,
        List<ArrayList<T>> children, Context cxt) {
    this.group = group;
    this.children = children;
    this.context = cxt;
}

@Override
public Object[] getChild(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    // return children[groupPosition][childPosition];
    // return children.get(groupPosition).get(groupPosition);
    Object temp[] = {
            children.get(groupPosition).get(childPosition)
                    .getProcedureName(),
            children.get(groupPosition).get(childPosition)
                    .getRecoveryStartTime(),
            children.get(groupPosition).get(childPosition)
                    .getRecoveryEndTime(),
            children.get(groupPosition).get(childPosition)
                    .getCheckStartTime(),
            children.get(groupPosition).get(childPosition)
                    .getCheckEndTime(),
            children.get(groupPosition).get(childPosition).getOperator() };

    return temp;

}

@Override
public long getChildId(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    return childPosition;
}

@Override
public View getChildView(int groupPosition, int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    TableLayout tl = new TableLayout(context);
    tl.setStretchAllColumns(true);
    TableRow tr = new TableRow(context);

    for (int i = 0; i <= getChild(groupPosition, childPosition).length - 1; i++) {

        final EditText editText = getChildTextView();
        editText.setText(getChild(groupPosition, childPosition)[i]
                .toString());

        editText.setClickable(true);
        editText.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                // TODO Auto-generated method stub
                editText.setText(getCurrentTime());

                return true;

            }
        });

        tr.addView(editText);
    }
        Button button = new Button(context);
        button.setText("提交");
        button.setTextSize(8);
        button.setGravity(Gravity.CENTER);
        tr.addView(button);
        tl.addView(tr);


    return tl;
    // TextView textView = getTextView();
    // textView.setText(getChild(groupPosition, childPosition).toString());
    // return textView;
}

@Override
public int getChildrenCount(int groupPosition) {
    // TODO Auto-generated method stub
    // return children[groupPosition].length;
    return children.get(groupPosition).size();
}

@Override
public Object getGroup(int groupPosition) {
    // TODO Auto-generated method stub
    // return group[groupPosition];
    return group.get(groupPosition);
}

@Override
public int getGroupCount() {
    // TODO Auto-generated method stub
    // return group.length;
    return group.size();
}

@Override
public long getGroupId(int groupPosition) {
    // TODO Auto-generated method stub
    return groupPosition;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    LinearLayout ll = new LinearLayout(context);
    ll.setOrientation(0);
    TextView textView = getGroupTextView();
    textView.setText(getGroup(groupPosition).toString());
    ll.addView(textView);
    return ll;
}

@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;
}

private TextView getGroupTextView() {
    AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, 64);
    TextView textView = new TextView(context);
    textView.setLayoutParams(lp);
    textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    textView.setPadding(36, 0, 0, 0);
    textView.setTextSize(15);
    return textView;
}

private EditText getChildTextView() {
    // AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
    // ViewGroup.LayoutParams.WRAP_CONTENT, 32);
    EditText editText = new EditText(context);
    // textView.setLayoutParams(lp);
    editText.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    editText.setPadding(36, 0, 0, 0);

    editText.setTextSize(8);
    return editText;
}

String getCurrentTime() {
    int year = 0;
    int month = 0;
    int day = 0;
    int hour = 0;
    int minute = 0;
    int second = 0;

    Calendar calendar = Calendar.getInstance();

    year = calendar.get(Calendar.YEAR);
    month = calendar.get(Calendar.MONTH);
    day = calendar.get(Calendar.DAY_OF_MONTH);
    hour = calendar.get(Calendar.HOUR);
    minute = calendar.get(Calendar.MINUTE);
    second = calendar.get(Calendar.SECOND);

    String currentTime = year + "/" + (month + 1) + "/" + (day + 1) + "\n"
            + (hour + 1) + ":" + minute + ":" + second;
    return currentTime;

}

}

package com.example.expandablelisttest;

import java.util.ArrayList;
import java.util.Date;

import android.widget.TextView;

public class T {

private String procedureName;
private String recoveryStartTime;
private String recoveryEndTime;
private String checkStartTime;
private String checkEndTime;
private String operator;




public String getProcedureName() {
    return procedureName ;
}

public void setProcedureName(String procedureName) {
    this.procedureName = procedureName;
}

public String getRecoveryStartTime() {
    return recoveryStartTime;
}

public void setRecoveryStartTime(String recoveryStartTime) {
    this.recoveryStartTime = recoveryStartTime;
}

public String getRecoveryEndTime() {
    return recoveryEndTime;
}

public void setRecoveryEndTime(String recoveryEndTime) {
    this.recoveryEndTime = recoveryEndTime;
}

public String getCheckStartTime() {
    return checkStartTime;
}

public void setCheckStartTime(String checkStartTime) {
    this.checkStartTime = checkStartTime;
}

public String getCheckEndTime() {
    return checkEndTime;
}

public void setCheckEndTime(String checkEndTime) {
    this.checkEndTime = checkEndTime;
}

public String getOperator() {
    return operator;
}

public void setOperator(String operator) {
    this.operator = operator;
}

}

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 Arcgis相交分析无法绘制一个或多个图形
    • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
    • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
    • ¥30 3天&7天&&15天&销量如何统计同一行
    • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题
    • ¥20 云服务Linux系统TCP-MSS值修改?
    • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)