将数据发送到其他布局

时间:2017-02-25 19:04:40

标签: java android android-layout spinner android-spinner

我有旋转器的活动。我想要的是:在按钮点击后添加具有相同数据的新旋转器。一切都显示在图片上。是的,我是新手,对每一个错误都很抱歉:)

度过愉快的一天

enter image description here

public class NaujasUzsakymasList extends ActionBarActivity {
PrekesDBController controller = new PrekesDBController(this);
ListView ls;
ScrollView sv;
TextView infotext;
CheckBox check;
LinearLayout ll;
EditText vnt;
private Spinner spinner1, spinner2;
private Button btnSubmit, btnprideti;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.naujasuzsakymailist);
    ScrollView sv = (ScrollView) findViewById(R.id.myscroll);
    LinearLayout ll = (LinearLayout) findViewById(R.id.mylinearLayout);

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // delete = (Button) findViewById(R.id.btndel);
    ls = (ListView) findViewById(R.id.prekeslist);
    infotext = (TextView) findViewById(R.id.txtresulttext);
    spinner1 = (Spinner) findViewById(R.id.spinner1);
    spinner2 = (Spinner) findViewById(R.id.spinner2);
    btnSubmit = (Button) findViewById(R.id.btnSubmit);
    btnprideti = (Button) findViewById(R.id.prideti);
    // check = (CheckBox) findViewById(R.id.checkBox4);
    // vnt = (EditText) findViewById(R.id.editText2);
    addItemsOnSpinner2();
    addItemsOnSpinner1();
    addListenerOnButton();
    addListenerOnButtonprideti();
    addListenerOnSpinnerItemSelection();


}

/// delete.setOnClickListener(new View.OnClickListener() {
// @Override
//public void onClick(View v) {
//  controller = new UzsakymaiDBController(getApplicationContext());
/// SQLiteDatabase db = controller.getWritableDatabase();
// db.delete("uzsakymai", "uzsakymoid=" + txtuzsakymoid, null);
// }

//  });
//   @Override
//  public boolean onCreateOptionsMenu(Menu menu) {
//    getMenuInflater().inflate(R.menu.menu_main, menu);
//   return true;
// }
public void addItemsOnSpinner2() {
    setContentView(R.layout.naujasuzsakymailist);
    spinner2 = (Spinner) findViewById(R.id.spinner2);
    List<String> list = new ArrayList<String>();
    list.add("1");
    list.add("2");
    list.add("3");
    list.add("4");
    list.add("5");
    list.add("6");
    list.add("7");
    list.add("8");
    list.add("9");
    list.add("10");
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner2.setAdapter(dataAdapter);
}
public void addItemsOnSpinner1() {

    spinner1 = (Spinner) findViewById(R.id.spinner1);
   // ArrayList<HashMap<String, String>> data2 = controller.getpavadinimas();
    ArrayList<HashMap<String, String>> data2 = controller.getpavadinimas();
    int i = 0;
    final String pavadinimas[] = new String[data2.size()];
    for (HashMap<String, String> hashMap : data2) {
        for (String value : hashMap.values()) {
            pavadinimas[i] = value ;
            i++;

        }
    }

    List<String> arrayList = new ArrayList<>();
    Collections.addAll(arrayList, pavadinimas);


    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, arrayList);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner1.setAdapter(dataAdapter);


}




public void addListenerOnSpinnerItemSelection() {
    spinner1 = (Spinner) findViewById(R.id.spinner1);
    spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
}

// get the selected dropdown list value
public void addListenerOnButton() {

    spinner1 = (Spinner) findViewById(R.id.spinner1);
    spinner2 = (Spinner) findViewById(R.id.spinner2);
    btnSubmit = (Button) findViewById(R.id.btnSubmit);

    btnSubmit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            Toast.makeText(NaujasUzsakymasList.this,
                    "OnClickListener : " +
                            "\nSpinner 1 : "+ String.valueOf(spinner1.getSelectedItem()) +
                            "\nSpinner 2 : "+ String.valueOf(spinner2.getSelectedItem()),
                    Toast.LENGTH_SHORT).show();
        }

    });

}

public void addListenerOnButtonprideti() {

    spinner1 = (Spinner) findViewById(R.id.spinner1);
    spinner2 = (Spinner) findViewById(R.id.spinner2);
    btnprideti = (Button) findViewById(R.id.prideti);




    for (int j = 0; j < 20; j++) {
        btnprideti.setOnClickListener(new View.OnClickListener() {
            int j = 0;
            @Override

            public void onClick(View v) {


                ScrollView sv = (ScrollView) findViewById(R.id.myscroll);
                LinearLayout ll = (LinearLayout) findViewById(R.id.mylinearLayout);

                LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);


                View view = inflater.inflate(R.layout.naujasuzsakymailist12, null);
              // Button btnprideti = (Button) view.findViewById(R.id.spinner1);

                Spinner spinner1 = (Spinner) view.findViewById(R.id.spinner1);
                Spinner spinner2 = (Spinner) view.findViewById(R.id.spinner2);



             // btnprideti.setText("Nr." + j);
                //cb.isChecked();
                ll.addView(view);

                j++;
            }

        });
    }

}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
private void DisplayToast(String msg) {
    Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT).show();
}}

0 个答案:

没有答案