来自微调器的TextView setText

时间:2018-02-06 23:16:35

标签: android

从spinner中选择item后,我将textView设置为certian int。 我从字符串值中选择项目而不是cije,这是textview的名称应该将自己设置为我之前添加的一些变量

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.tab1, container, false);
    String [] values =
                   {"----",
                    "Topli sendvič",
                    "Ćevapi mali",
                    "Ćevapi srednji",
                    "Ćevapi veliki",
                    "Hot dog",
                    "Hamburger",
                    "Pomfrit"};
    TextView cijena = (TextView) v.findViewById(R.id.cijena);
    Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, values);
    adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
    spinner.setAdapter(adapter);
    if(spinner.equals("Topli sendvič"))
    {
        cijena.setText((int)jedkm);
    }
    if(spinner.equals("Pomfrit"))
    {
        cijena.setText((int)jedkm);
    }
    if(spinner.equals("Hot dog"))
    {
        cijena.setText((int)jedkm);
    }
    if(spinner.equals("Hamburger"))
    {
        cijena.setText((int)jedipokm);
    }
    if(spinner.equals("Ćevapi mali"))
    {
        cijena.setText((int)dvekm);
    }
    if(spinner.equals("Ćevapi srednji"))
    {
        cijena.setText(2.5 +" KM");
    }
    if(spinner.equals("Ćevapi veliki"))
    {
        cijena.setText((int)trikm);
    }

    return v;

}

1 个答案:

答案 0 :(得分:0)

使用setOnItemSelectedListener上的Spinner功能。

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        // get selected item and assign to textview
        // ex: textView.setText(spinner.getSelectedItem().toString());
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
        // handle if you'd like to
    }
});