java-Expandlelistview动态更新

问题描述

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

}

时间: 2024-11-01 14:39:00

java-Expandlelistview动态更新的相关文章

java 跳转 动态更新页面数据

问题描述 java 跳转 动态更新页面数据 主页面include一个jsp的增删改页面,数据变动,怎么更新主页面的数据,request.getRequestDispatcher().forward(),地址栏不变,而且主页面数据也不变, response.sendRedirect重定向到主页面地址栏变,数据更新,不是include的list页面, 该怎么做? 解决方案 一般你的页面按钮,例如增加按钮,在后台处理完成后,后台页面跳转到这个查询页面来啊.即所有增.删除.改操作完成后的后台action

Android编程实现动态更新ListView的方法_Android

本文实例讲述了Android编程实现动态更新ListView的方法.分享给大家供大家参考,具体如下: 有时候我们需要修改已经生成的列表,添加或者修改数据,notifyDataSetChanged()可以在修改适配器绑定的数组后,不用重新刷新Activity,通知Activity更新ListView.今天的例子就是通过Handler AsyncTask两种方式来动态更新ListView.从今天起,每次学习的源代码都会打包上传,方便各位同学学习,注册帐号即可下载. 布局main.xml: <?xml

Android零基础入门第44节:ListView数据动态更新

原文:Android零基础入门第44节:ListView数据动态更新    经过前面几期的学习,关于ListView的一些基本用法大概学的差不多了,但是你可能发现了,所有ListView里面要填充的数据都是静态的,但在实际开发中,这些数据往往都是动态变化的,比如数据内容发生改变.增加几行.或者删除几行,这就涉及到ListView数据的更新问题.     接下来通过一个简单的示例程序来学习ListView的数据更新.     继续使用WidgetSample工程,在app/main/res/lay

仿百度壁纸客户端(五)——实现搜索动画GestureDetector手势识别,动态更新搜索关键字

仿百度壁纸客户端(五)--实现搜索动画GestureDetector手势识别,动态更新搜索关键字 百度壁纸系列 仿百度壁纸客户端(一)--主框架搭建,自定义Tab + ViewPager + Fragment 仿百度壁纸客户端(二)--主页自定义ViewPager广告定时轮播图 仿百度壁纸客户端(三)--首页单向,双向事件冲突处理,壁纸列表的实现 仿百度壁纸客户端(四)--自定义上拉加载实现精选壁纸墙 仿百度壁纸客户端(五)--实现搜索动画GestureDetector手势识别,动态更新搜索关键

jsp页面表单和数据库之间的动态更新

问题描述 if(rs1.next()) { lo = rs1.getString("lo"); la = rs1.getString("la"); %> <tr> <td width="200" height="29" align="center" ><%=rs.getString("teamID")%></td> <td wi

Android实现Listview异步加载网络图片并动态更新的方法_Android

本文实例讲述了Android实现Listview异步加载网络图片并动态更新的方法.分享给大家供大家参考,具体如下: 应用实例:解析后台返回的数据,把每条都显示在ListView中,包括活动图片.店名.活动详情.地址.电话和距离等. 在布局文件中ListView的定义: <ListView android:id="@id/maplistview" android:background="@drawable/bg" android:layout_width=&qu

Android通过Handler与AsyncTask两种方式动态更新ListView(附源码)_Android

本文实例讲述了Android通过Handler与AsyncTask两种方式动态更新ListView的方法.分享给大家供大家参考,具体如下: 有时候我们需要修改已经生成的列表,添加或者修改数据,notifyDataSetChanged()可以在修改适配器绑定的数组后,不用重新刷新Activity,通知Activity更新ListView.今天的例子就是通过Handler AsyncTask两种方式来动态更新ListView. 布局main.xml: <?xml version="1.0&qu

Android实现Listview异步加载网络图片并动态更新的方法

本文实例讲述了Android实现Listview异步加载网络图片并动态更新的方法.分享给大家供大家参考,具体如下: 应用实例:解析后台返回的数据,把每条都显示在ListView中,包括活动图片.店名.活动详情.地址.电话和距离等. 在布局文件中ListView的定义: <ListView android:id="@id/maplistview" android:background="@drawable/bg" android:layout_width=&qu

iOS 利用 framework 进行动态更新

前言 目前 iOS 上的动态更新方案主要有以下 4 种: HTML 5 lua(wax)hotpatch react native framework 前面三种都是通过在应用内搭建一个运行环境来实现动态更新(HTML 5 是原生支持),在用户体验.与系统交互上有一定的限制,对开发者的要求也更高(至少得熟悉 lua 或者 js). 使用 framework 的方式来更新可以不依赖第三方库,使用原生的 OC/Swift 来开发,体验更好,开发成本也更低. 由于 Apple 不希望开发者绕过 App