我做了一个只有一组的可扩展视图,单击一个按钮,一个新的
添加该组中的行,这些行在输入时包含文本框中的一些数据
从行中,我发现当我添加 4 行时我得到 7 行输入,总是这样
口粮,当添加 5 行时,我得到 8 行输入,不明白尝试做很多
技巧。
你能帮我从这些行中获取输入的最佳方法是什么。actlist 是接受输入的数组列表。在下面有代码活动
public class AddActActivity extends ExpandableListActivity implements
OnGroupClickListener,OnClickListener {
/** Called when the activity is first created. */
public TextView ShowTitle;
public TextView Date;
public static long cuesheetnimber;
public static ExpandableListView expandableListView;
public static ActAdapter expListAdapter;
static ArrayList<String> groupNames = new ArrayList<String>();
static ArrayList<ArrayList<Acts>> obsList = new ArrayList<ArrayList<Acts>>
();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addact);
ShowTitle = (TextView)findViewById(R.id.showtitleact);
ShowTitle.setText(getIntent().getStringExtra("ShowTitle"));
Date = (TextView)findViewById(R.id.showdateact);
Date.setText(DateSpinner.date);
cuesheetnimber=getIntent().getLongExtra("_ID", 0);
expandableListView =getExpandableListView();
expandableListView.setOnGroupClickListener(this);
expListAdapter = new ActAdapter( this,groupNames, obsList );
setListAdapter( expListAdapter );
expListAdapter.groups.add("a");
//AUDITDATA.HCWlist[AUDITDATA.row]=AUDITDATA.HCWNAME;
ArrayList<Acts> obs = new ArrayList<Acts>();
obs.add(new Acts());
//AUDITDATA.row++;
expListAdapter.childs.add(obs);
expandableListView.expandGroup(0);
expListAdapter.notifyDataSetChanged();
Button add=(Button)findViewById(R.id.button_add_act);
add.setOnClickListener(this);
Button SaveandExit=(Button)findViewById(R.id.SaveandExit);
SaveandExit.setOnClickListener(this);
}
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button_add_act:
Button b=(Button)v;
b.setText("Add Another Act");
expListAdapter.addHcwGroup(expandableListView);
// expListAdapter.notifyDataSetChanged();
break;
case R.id.SaveandExit:
// expListAdapter.notifyDataSetChanged();
saveandexit();
clear();
finish();
break;
default:
break;
}
}
private void clear() {
// TODO Auto-generated method stub
ActAdapter.actlist.clear();
ActAdapter.groups.clear();
ActAdapter.childs.clear();
}
@Override
public void onBackPressed() {
ActAdapter.actlist.clear();
ActAdapter.groups.clear();
ActAdapter.childs.clear();
// TODO Auto-generated method stub
super.onBackPressed();
}
private void saveandexit() {
// TODO Auto-generated method stub
for (Acts act :ActAdapter.actlist) {
Init.setActs(this, act);
}
}
}
And here is adapter code
;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.TimePicker;
public class ActAdapter extends BaseExpandableListAdapter {
public static int staticindex = 0;
private Context context;
static public ArrayList<String> groups;
static public ArrayList<ArrayList<Acts>> childs;
private LayoutInflater inflater;
public boolean flag = false;
public ActAdapter(Context context, ArrayList<String> groups,
ArrayList<ArrayList<Acts>> childs) {
this.context = context;
this.groups = groups;
this.childs = childs;
inflater = LayoutInflater.from(context);
}
public Object getChild(int groupPosition, int childPosition) {
return childs.get(groupPosition).get(childPosition);
}
public long getChildId(int groupPosition, int childPosition) {
return (long) (groupPosition * 1024 + childPosition); // Max 1024
// children per
// group
}
public void setChilds(ArrayList<ArrayList<Acts>> childs) {
this.childs = childs;
}
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
View v = null;
long ShowID=AddActActivity.cuesheetnimber;
EditText ACTNUMBER;
EditText ACTTITLE;
TimePicker STARTTIME;
TimePicker ENDTIME;
EditText ACTIONDATA;
EditText NOTE;
if (convertView != null) {
v = convertView;
Log.d("dfg", groupPosition+"act set"+childPosition);
ACTNUMBER = (EditText) v.findViewById(R.id.ActionNumber);
ACTTITLE = (EditText) v.findViewById(R.id.ActionTitle);
STARTTIME = (TimePicker) v.findViewById(R.id.starttime);
ENDTIME = (TimePicker) v.findViewById(R.id.endttime);
ACTIONDATA = (EditText) v.findViewById(R.id.Actionname);
NOTE = (EditText) v.findViewById(R.id.Noteact);
Acts acts = new Acts();
acts.setShowID(ShowID + "");
acts.setACTIONDATA(ACTIONDATA.getText().toString());
acts.setACTNUMBER(ACTNUMBER.getText().toString());
acts.setNOTE(NOTE.getText().toString());
acts.setACTTITLE(ACTTITLE.getText().toString());
acts.setENDTIME(ENDTIME.getCurrentHour().toString() + "x"
+ ENDTIME.getCurrentMinute().toString());
acts.setSTARTTIME(STARTTIME.getCurrentHour().toString() +
"x"
+ STARTTIME.getCurrentMinute().toString());
actlist.add(acts);
} else {Log.d("dfg", "chil null");
actlist.clear();
v = inflater.inflate(R.layout.act_child_row, parent,
false);
}
return v;
}
public int getChildrenCount(int groupPosition) {
if (groupPosition > (groups.size() - 1))
return 0;
return childs.get(groupPosition).size();
}
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
public int getGroupCount() {
return groups.size();
}
public long getGroupId(int groupPosition) {
return (long) (groupPosition * 1024); // To be consistent with
// getChildId
}
static int po = 0;
public static ArrayList<Acts> actlist = new ArrayList<Acts>();
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
po++;
View v = null;
if (convertView != null) {
v = convertView;
Log.d("dfg", "grp reloaded");
} else {
v = inflater.inflate(R.layout.act_group_row, parent, false);
Log.d("dfg", "grp created");
}
;
return v;
}
public static void save()
{}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public void addHcwGroup(ExpandableListView expandableListView) {
childs.get(0).add(new Acts());
notifyDataSetChanged();
}
public void onGroupCollapsed(int groupPosition) {
}
public void onGroupExpanded(int groupPosition) {
}
}
感谢您尝试提供帮助