创建新组并将名称和号码添加为新组的联系人。在创建按钮上创建新组

时间:2016-02-03 05:41:02

标签: android android-layout

public class Group extends AppCompatActivity {

String Name, Number;

Context context = null;
String Result = null;

private EditText ed_Group_Name, ed_Name, ed_Number;
private Button btn_View, btn_Create,btn_Add_Contact, btn_New_Group, btn_Cancel;
private ListView lv_Group;
private LinearLayout ll_Action, ll_Create_New_Group, ll_Show_List;

ArrayList<String> Group_Name =  new ArrayList<String>();
ArrayList<String[]> list1 = new ArrayList<String[]>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_group);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    GroupList group_data[] = new GroupList[]
            {
                    new GroupList(R.drawable.group, "My Family (10)"),
                    new GroupList(R.drawable.group, "Rahuri (40)"),
                    new GroupList(R.drawable.group, "Lekha Nagar (700)"),
                    new GroupList(R.drawable.group, "Friends Forever (50)"),
                    new GroupList(R.drawable.group, "Parivar (100)"),
                    new GroupList(R.drawable.group, "Mhasrul Friends (100)")
            };

    GroupAdapter adapter = new GroupAdapter(this, R.layout.group_item_row, group_data);

    lv_Group = (ListView) findViewById(R.id.lv_group);
    lv_Group.setAdapter(adapter);

    lv_Group.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Intent intent = new Intent(getApplicationContext(), Message.class);
            startActivity(intent);
        }
    });

    ll_Action = (LinearLayout) findViewById(R.id.ll_action);
    ll_Show_List = (LinearLayout) findViewById(R.id.ll_show_list);
    ll_Create_New_Group = (LinearLayout) findViewById(R.id.ll_create_group);
    btn_View = (Button) findViewById(R.id.btn_view_group);
    btn_Create = (Button) findViewById(R.id.btn_create_group);
    btn_Add_Contact = (Button) findViewById(R.id.btn_add_cnt);
    btn_New_Group = (Button) findViewById(R.id.btn_create_new_grp);
    btn_Cancel = (Button) findViewById(R.id.btn_cancel);
    ed_Group_Name = (EditText) findViewById(R.id.ed_grp_name);
    ed_Name = (EditText) findViewById(R.id.ed_add_name);
    ed_Number = (EditText) findViewById(R.id.ed_add_no);
    lv_Group = (ListView) findViewById(R.id.lv_group);

    btn_View.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            ll_Show_List.setVisibility(View.VISIBLE);
            ll_Create_New_Group.setVisibility(View.GONE);
        }
    });

    btn_Create.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            ll_Create_New_Group.setVisibility(View.VISIBLE);
            ll_Show_List.setVisibility(View.GONE);
            ll_Action.setVisibility(View.GONE);

        }
    });

    btn_Add_Contact.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            int count = 0;
            do {
                Name = ed_Name.getText().toString().trim();
                Number = ed_Number.getText().toString().trim();
                String contact = Name.concat(" "+Number);
                Group_Name.add(contact);
                count ++;
            }while (Group_Name.size()< count);

            ed_Name.setText("");
            ed_Number.setText("");
            ed_Name.requestFocus();
        }
    });

    btn_Cancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(getApplicationContext(), Group.class);
            startActivity(intent);
        }
    });

    btn_New_Group.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            ll_Show_List.setVisibility(View.VISIBLE);
            ll_Action.setVisibility(View.VISIBLE);
            ll_Create_New_Group.setVisibility(View.GONE);

            String[] simpleArray = new String[Group_Name.size()];
            list1.add(simpleArray);
            ArrayAdapter<String> adapter =
                    new ArrayAdapter<String>(getApplicationContext(), R.layout.group_item_row,
                            R.id.tv_cnt, Group_Name.toArray(simpleArray));
            lv_Group.setAdapter(adapter);

            //new createGroup().execute();
        }
    });
} }

0 个答案:

没有答案