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