1

我是 android 新手,在我正在开发的应用程序中,我想添加一个包含注册页面的可扩展列表视图。可以是这样的

   Add Personal Details +
       name(edittext)
       ph_no(edittext)
       email_id(edittext)
       Save Button


  Add Acocunt Details +
      Transaction_id(edittext)
      Transaction_type(edittext)
      Total_amount(edittext)
      Save Button

ETC....

怎么可能?

4

3 回答 3

0

您可以使用 ExpandableListView 和 customAdapter

这里的activity实现了onChildClickListener onGroupCollapseListener和onGroupExpandListener

请注意,我只是直接输入代码,可能存在编译错误,请修复,如果有任何问题,请发表评论

   public class YourActivity extends Activity implements OnChildClickListener, OnGroupCollapseListener{

private ExpandableListView exList= null;
private ExpandableListAdapter mAdapter = null;

//add all unimplemented methods

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    placeHolder = (LinearLayout) findViewById(R.id.placeHolder);

    exList= (ExpandableListView) findViewById(R.id.wl_list);

    exList.setHorizontalFadingEdgeEnabled(true);
    exList.setFastScrollEnabled(true);
    exList.setHorizontalFadingEdgeEnabled(true);
    exList.setFadingEdgeLength(30);
    exList.setDividerHeight(1);
    exList.isFocusable();
    exList.setTextFilterEnabled(true);
    exList.setSelectionAfterHeaderView();
    exList.setSelected(true);

    exList.setOnChildClickListener(this);
    mAdapter = new ExpandableListAdapter(this);
    exList.setAdapter(mAdapter);

    exList.setOnGroupCollapseListener(this);
    exList.setOnGroupExpandListener(this);

    setContentView(exList); 

}


public void onGroupCollapse(int groupPosition) {

    // do whatever additional
    exList.collapseGroup(groupPosition);
}

public void onGroupExpand(int groupPosition) {

    // do whatever additional
    exList.expandGroup(groupPosition);
}

}

和一个自定义适配器,我只实现了 getChildView() 方法,请对 getGroupView() 方法执行相同的操作以完成

    public class ExpandableListAdapter extends BaseExpandableListAdapter {
                private Activity activity;

        public ExpandableListAdapter(Activity activity) {
            this.activity = activity;
        }

        public View getCustomChildView(int groupPosition, int childPosition) {
            WORKLIST_HEADER wfHeader = null;
            //View view = null;
            //if (view == null) {
                // you can do this also, if you prefer filling up screens via xml, that is, inflate
                //view = inflater.inflate(R.layout.wl_list_row, null);
            //}


            //or jus create a linear layout manually and add views to it like below and return the linear layout, this should do
                TextView textView = null;
                LinearLayout wflayout = new LinearLayout(activity);    


                textView = new TextView(activity);
                textView.setText("name");
                textView.setTextAppearance(activity, R.style.boldText);

                wflayout.addView(textView);

                textView = new TextView(activity);
                textView.setText("email_id");
                textView.setTextAppearance(activity, R.style.boldText);



                wflayout.addView(textView);

// add more and button as well,

        //return linear layout
            return wflayout;
        }

        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                View convertView, ViewGroup parent) {
                return getCustomChildView(groupPosition, childPosition);
        }


    // add otehr  unimplemented methods


    }
于 2012-12-26T07:14:22.500 回答
0

您必须为您的可扩展列表视图创建自定义适配器。

于 2012-12-26T06:22:40.843 回答
0

您可以使用水平方向的 linearlayout 并为每个 linearlayout 分配名称。这样您就可以在单个 xml 文件中展开以使用可展开的列表视图。

于 2012-12-26T07:33:37.527 回答