单击“保存”按钮时,在单独的活动中创建ImageButton?

时间:2017-04-16 10:51:11

标签: java android imagebutton android-imagebutton

我试图做一些与众不同的事情。我有一个添加个人资料页面,用户可以在其中添加多个个人资料。我想在主页上将这些配置文件表示为圆圈(ImageButtons)。

非常类似: enter image description here

因此,当用户保存个人资料时,如何将这些圈子中的一个添加到此水平滚动视图中?我希望创建的圆圈在创建的客户名称的第一个字母中包含一个字母。 我想这需要我已经创建了所有26个字母的字母,但这没有问题。

有关如何执行此操作的任何建议?如果我不清楚,我很抱歉,我很乐意发布更多代码或澄清任何内容。我使用的数据库是Firebase。我正在运行最新版本的Android Studio。

非常感谢任何帮助,为人们欢呼!

AddAProfile.java:

public class AddProfileActivity extends AppCompatActivity {

    EditText etName;
    EditText etCareer;
    CheckBox cbTech;
    CheckBox cbMedi;
    CheckBox nfRenewableEnergy;
    CheckBox nfGoogle;
    CheckBox cfNovartis;
    CheckBox nfTesla;
    CheckBox lrsFB;
    CheckBox lrsAAPL;
    CheckBox lrsYHOO;
    CheckBox cbEURUSD;
    CheckBox lrcuUSDRUB;
    CheckBox lrcoSILVER;
    CheckBox lrcoGOLD;
    CheckBox lrcuGBPUSD;
    CheckBox lriNSDQ;
    CheckBox lriSP500;
    Button bSave;



    DatabaseReference databaseClients;


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

        databaseClients = FirebaseDatabase.getInstance().getReference("clients");

         etName = (EditText) findViewById(R.id.etName);
         etCareer = (EditText) findViewById(R.id.etCareer);
         cbTech = (CheckBox) findViewById(R.id.cbTech);
         cbMedi = (CheckBox) findViewById(R.id.cbMedi);
         nfRenewableEnergy = (CheckBox) findViewById(R.id.nfRenewableEnergy);
        nfGoogle = (CheckBox) findViewById(R.id.nfGoogle);
        cfNovartis = (CheckBox) findViewById(R.id.cfNovartis);
        nfTesla = (CheckBox) findViewById(R.id.nfTesla);
        lrsFB = (CheckBox) findViewById(R.id.lrsFB);
        lrsAAPL = (CheckBox) findViewById(R.id.lrsAAPL);
        lrsYHOO = (CheckBox) findViewById(R.id.lrsYHOO);
        cbEURUSD = (CheckBox) findViewById(R.id.cbEURUSD);
        lrcuUSDRUB = (CheckBox) findViewById(R.id.lrcuUSDRUB);
        lrcoSILVER = (CheckBox) findViewById(R.id.lrcoSILVER);
        lrcoGOLD = (CheckBox) findViewById(R.id.lrcoGOLD);
        lrcuGBPUSD = (CheckBox) findViewById(R.id.lrcuGBPUSD);
        lriNSDQ = (CheckBox) findViewById(R.id.lriNSDQ);
        lriSP500 = (CheckBox) findViewById(R.id.lriSP500);
        bSave = (Button) findViewById(R.id.bSave);


        ImageButton bSettingsBlack = (ImageButton) findViewById(R.id.ibSettingsBlack);
        ImageButton bEconCalBlack = (ImageButton) findViewById(R.id.ibEconCalBlack);
        ImageButton bLiveRates = (ImageButton) findViewById(R.id.ibLiveRates);
        ImageButton bNewsBlack = (ImageButton) findViewById(R.id.ibNewsBlack);

        bSettingsBlack.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(AddProfileActivity.this, SettingsActivity.class));
            }
        });
        bEconCalBlack.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(AddProfileActivity.this, WebViewActivity.class));
            }
        });
        bLiveRates.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(AddProfileActivity.this, sortingrates.class));
            }
        });
        bNewsBlack.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(AddProfileActivity.this, HomePageNews.class));
            }
        });

        bSave.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                bSave();

            }
        });



    }

    private void bSave(){
        String name = etName.getText().toString().trim();
        String career = etCareer.getText().toString().trim();
        Boolean techCB = cbTech.isChecked();
        Boolean mediCB = cbMedi.isChecked();
        Boolean renewableEnergyNF = nfRenewableEnergy.isChecked();
        Boolean googleNF = nfGoogle.isChecked();
        Boolean novartisNF = cfNovartis.isChecked();
        Boolean teslaNF = nfTesla.isChecked();
        Boolean fbLRS = lrsFB.isChecked();
        Boolean applLRS = lrsAAPL.isChecked();
        Boolean yhooLRS = lrsYHOO.isChecked();
        Boolean eurusdCB = cbEURUSD.isChecked();
        Boolean usdrubCU = lrcuUSDRUB.isChecked();
        Boolean silverCO = lrcoSILVER.isChecked();
        Boolean goldCO = lrcoGOLD.isChecked();
        Boolean gbpusdCU = lrcuGBPUSD.isChecked();
        Boolean nsdqI = lriNSDQ.isChecked();
        Boolean sp500I = lriSP500.isChecked();


        if(!TextUtils.isEmpty(name)){
          String id =  databaseClients.push().getKey();

            Clients clients = new Clients(id, name, career, techCB, mediCB, renewableEnergyNF, googleNF,
                    novartisNF, teslaNF, fbLRS, applLRS, yhooLRS, eurusdCB, usdrubCU, silverCO,
                    goldCO, gbpusdCU, nsdqI, sp500I );

            databaseClients.child(id).setValue(clients);

            Toast.makeText(this, "Client added", Toast.LENGTH_LONG).show();

            startActivity(new Intent(AddProfileActivity.this, AddProfileActivity.class));



        }else{
            Toast.makeText(this, "Please enter your name", Toast.LENGTH_LONG).show();

        }


    }

}

编辑(我尝试过的): 我厌倦了其他按钮作为改变图像的实验,因为我无法想出直接创建它。

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main17);

        ImageView view = (ImageView) findViewById(R.id.imageView3);
        view.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                ImageView imageView = (ImageView) view;
                assert(R.id.imageView3 == imageView.getId());
                Integer integer = (Integer) imageView.getTag();
                integer = integer == null ? 0 : integer;
                switch(integer) {
                    case R.drawable.circlesambergrey2:
                        imageView.setImageResource(R.drawable.bell);
                        imageView.setTag(R.drawable.bell);
                        break;
                    case R.drawable.bell:
                    default:
                        imageView.setImageResource(R.drawable.circlesambergrey2);
                        imageView.setTag(R.drawable.circlesambergrey2);
                        break;}
                }
            });
        }

我还认为用户可以使用旋转器中正确的字母选择图像按钮。这就是我目前正在尝试的!欢呼声。

0 个答案:

没有答案