1

私はAndroidを初めて使用し、開発中のアプリで、登録ページを含むexpandablelistviewを追加したいと考えています。このようにすることができます、

   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

等....

どうすればそれが可能ですか?

4

3 に答える 3

0

水平方向のlinearlayoutを使用して、すべてのlinearlayoutに名前を割り当てることができます。単一のxmlファイルで拡張可能なリストビューを使用するように拡張できるようにします。

于 2012-12-26T07:33:37.527 に答える
0

拡張可能なリストビュー用にカスタマイズされたアダプタを作成する必要があります。

于 2012-12-26T06:22:40.843 に答える
0

ExpandableListViewとcustomAdapterを使用できます

ここでのアクティビティは、onChildClickListeneronGroupCollapseListenerと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 に答える