为什么日志没有打印? 所有其他人的日志都有效,但不适合孩子。
文本视图的日志确实出现,但是当我使用编辑文本时,它不起作用。
为什么这样?我哪里错了?
ExpandableListView expListView;
expListView = getExpandableListView();
expListView.setAdapter(new ExAdapter(this));
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
// TODO Auto-generated method stub
}
});
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
// TODO Auto-generated method stub
}
});
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Log.i("Tag", "-------------------------------------------------");
return true;
}
});
代码编辑---------
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if(convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.name_child, null);
}
TextView txtFName = (TextView) convertView.findViewById(R.id.txtFname);
txtFName.setText(arrChildhintelements[groupPosition][childPosition]);
editFName = (EditText) convertView.findViewById(R.id.editFName);
editFName.setHint(arrChildhintelements[groupPosition][childPosition]);
editFName.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//doing somthing....
return false;
}
});
return convertView;
}
答案 0 :(得分:3)
没有看到代码这只是一个猜测,但是childCLickListener可能正在使用该事件,因此它没有到达编辑文本,尝试在childClickListener中返回false
修改
好吧,我刚用你的代码创建了一个小项目,我无法触发onCildClickListener,将其更改为TextView,并且工作正常。它与EditText有关(可能它正在消耗该事件或者它没有注册为点击但是作为焦点的变化,但我只是在这一点猜测。)
所以在回答你的问题时,是否有可能 - 我不这么认为。但我确实做了一个可能有用的小解决方案。
将onTouchListener()附加到EditText并检查MotionEvent.ACTION_DOWN
答案 1 :(得分:0)
public class TryTestActivity extends ExpandableListActivity {
ExpandableListAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] titles = {"A","B","C"};
String[] fruits = {"a1","a2"};
String[] veggies = {"b1","b2","b3"};
String[] meats = {"c1","c2"};
String[][] contents = {fruits,veggies,meats};
String[][] edit_contents = {fruits,veggies,meats};
SimplerExpandableListAdapter adapter = new SimplerExpandableListAdapter(this,titles, contents, edit_contents);
setListAdapter(adapter);
getExpandableListView().setOnChildClickListener(this);
}
}
class SimplerExpandableListAdapter extends BaseExpandableListAdapter {
private Context mContext;
private String[][] mContents;
private String[] mTitles;
LayoutInflater inflater;
private CharSequence[][] mEditContents;
public SimplerExpandableListAdapter(Context context, String[] titles, String[][] contents, String[][] editContents) {
super();
if(titles.length != contents.length) {
throw new IllegalArgumentException("Titles and Contents must be the same size.");
}
mContext = context;
mContents = contents;
mTitles = titles;
mEditContents = editContents;
inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return mEditContents[groupPosition][childPosition];
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return groupPosition*childPosition;
}
@Override
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
//if(convertView == null)
{
convertView = inflater.inflate(R.layout.child_main, null);
}
TextView row1 = (TextView)convertView.findViewById(R.id.txt1);
EditText row2 = (EditText)convertView.findViewById(R.id.txt2);
row1.setText(mContents[groupPosition][childPosition]);
row2.setText(mEditContents[groupPosition][childPosition]);
row2.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
mEditContents[groupPosition][childPosition]=s.toString();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count){
//mEditContents[groupPosition][childPosition]=s.toString();
}
});
//row2.on
/*row2.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//some code...
return false;
}
});*/
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return mContents[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
return mContents[groupPosition];
}
@Override
public int getGroupCount() {
return mContents.length;
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
TextView row = (TextView)convertView;
if(row == null) {
row = new TextView(mContext);
}
row.setTypeface(Typeface.DEFAULT_BOLD);
row.setText(mTitles[groupPosition]);
return row;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
答案 2 :(得分:0)
把
myList.setOnChildClickListener(listAdapter);
。
然后onChildClick方法立即开始工作。