我已经使用ListActivity来显示一个视图,从一个xml布局文件膨胀。当我最初在列表中显示这个视图时,我通过将目标视图的visible属性设置为View.GONE来隐藏视图的一部分。在onListItemClick方法中,如果View.GONE可见,则将该'隐藏'视图的可见性设置为View.GONE。在下一次点击时,我想再次隐藏视图。为此,我检测视图的可见性,并将其更改为View.GONE(如果它是View.VISIBLE)。onListItemClick没有(总是)被ListActivity调用
我的代码执行方法onListItemClick,当隐藏视图的可见性os View.GONE并正确显示点击隐藏视图。但是,当视图的可见性设置为View.VISIBLE时,它不会执行onListItemClick方法。
据我所知,这种情况是使用ExpandableListActivity的好选择,但由于其他无法解决的问题,我无法使用它!
这里的(部分相关)代码:
public class MyListActivity extends ListActivity implements OnClickListener {
// images that depict whether part of the view is visible or not
private Drawable imgUp, imgDown;
private class MyOrderAdapter extends ArrayAdapter<Order> {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// infalte this view from xml
v = vi.inflate(R.layout.brief_order, null);
// display down arrow key depicting that more is available to be
// displayed when a user clicks on it.
ImageView arrow = (ImageView) v.findViewById(R.id.imgArrow);
// get a reference to the table layout for details
// which should not be displayed initially
TableLayout tb = (TableLayout) v.findViewById(R.id.view_detail);
// DO NOT DISPLAY PART OF THE VIEW INITIALLY
tb.setVisibility(View.GONE);
}
// code to initialize the text filed values in the view v
return v;
}
// onListItemClick
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Log.d("MyList", "item click called");
// RETRIEVE THE detail view
TableLayout tb = (TableLayout) v.findViewById(R.id.view_detail);
if(tb.getVisibility() == View.GONE) {
tb.setVisibility(View.VISIBLE);
img.setImageDrawable(imgUp);
}
else {
img.setImageDrawable(imgDown);
tb.setVisibility(View.GONE);
}
}
// rest of the code
}
感谢。
欢呼