0

1つのボタンをクリックすると、1つのグループのみで展開可能なビューを作成しました。

そのグループの行が追加されました。これらの行には、入力時にテキストボックスにデータが含まれています

行から、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) {
        }

    }

助けてくれてありがとう

4

1 に答える 1

1

長くなってしまい申し訳ありません。私はコードをテストしましたが、この質問に関連しているように見えますが、実際には何も間違っていません。私のシステムで何が起こっているかというと、ExapandableListActivityロードしてから追加ボタンをクリックすると、最初に2つの子行がロードされ、その後1つの子行がロードされます。しかし、アダプターは、ロードする準備ができている1行で開始されました。そして、あなたが認識しなければならないのは、あなたのExpandableListView初期化が崩壊したということです。.expandGroup();ボタンがクリックされるまでメソッドを呼び出しませんでした。これは、既にある行に2行目を追加した後です。それが理にかなっていることを願っています。あなたが何も示していないので、おそらくそれほど明白ではありませんgroupViewでした。

基本的に、私のアドバイスは、物事をより明確にするため.expandGroup();に、呼び出した直後にコマンドを呼び出すことです。setListAdapter();そうすれば、望む結果を得るために何を調整する必要があるかが明らかになるはずです。


質問を完全に誤解していたようです。editTexts で選択したすべての値を expandableList に自動的に保存できるようにしたいと考えています。もしそうなら、私はあなたが本当にあなたのデザインを再考すべきだとあなたに言います. これにリストビューを使用する際の問題は、行がビューから外れると完全に失われ、再作成する必要があるため、ビュー内のすべての値が失われることです。もちろんありますconvertViewただし、最近削除されたビューを意図的にではなく同じ位置に戻すことは絶対にないため、これは信頼できません。子行が表示されなくなると、子行がシャッフルされ続けますが、これは望ましくありません。getView でコレクションをクリアし続け、さらにユーザーがデータの入力を「終了」したときにデータをキャプチャする方法を考慮していないため、メソッドは確実に問題を引き起こします。

しかし、とにかくそれが必要な場合は、テキストウォッチャーをすべてに適用して、コレクション内の対応する値を常に調整させることができます。この手法は、次のYami's回答で強調されています: How to get values from grid view

しかし、これは面倒すぎると思います。TableLayoutすべてをメモリに保持し、すべてのビューをレイアウトに追加してから、これらのビューをそれぞれのコレクションに追加し、tablelayout のコンテンツをループして値を取得できるため、より有益であることがわかる場合があります。これは 1 つの代替手段ですが、多少管理しないとヒープサイズが影響を受ける可能性があります。

の各子行にボタンを組み込むと、パフォーマンスが向上しますExpandableListView。これにより、ボタンをクリックしたときにのみ、対応する行の内容がコレクションに保存されます。

今までは、私が考えられる解決策しか提供していませんでしたが、個人的にどのように対処するかを尋ねられたら、私はこれに の型を使用しませんListViewDialogこのコンポーネントをフォームとして認識し、代わりにこれを使用しようとします。次に、選択した場合は、詳細のセット全体を別のリストとして表示するだけで済みますが、詳細を入力するための xml インフレーションは 1 つしかありません。

于 2012-12-25T19:28:06.003 に答える