Android 中微调器的弹出菜单

发布于 2024-10-18 23:29:59 字数 1964 浏览 7 评论 0原文

我想要一个带有“A”、“B”、“C”项目的旋转器,

如果您选择“A”或“B”意味着计时器必须运行。

当选择项目“C”时,弹出窗口有 2 个打开的编辑文本和“确定”按钮。

如果您在编辑文本中键入“D”,则意味着在微调器中也添加了内容,同时添加了 chonometer 必须在此处运行

是我的代码:

public class Starttracker extends Activity {

PopupWindow popupWindow;


    String[] Items = {
                "A",
                "B",
                "C",
                "D",

        };

    Spinner s1;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.start);


  s1 = (Spinner) findViewById(R.id.spinner);

    final ArrayAdapter<String> adapter  = new ArrayAdapter<String>(
            this,android.R.layout.simple_spinner_item,Items);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    s1.setAdapter(adapter);
    s1.setOnItemSelectedListener(new OnItemSelectedListener()
    {
        public void onItemSelected(AdapterView<?> arg0, 
        View arg1, int arg2, long arg3) 
        {
            int index = s1.getSelectedItemPosition();
            Toast.makeText(getBaseContext(), 
                "You have selected item : " + Items[index], 
                Toast.LENGTH_SHORT).show(); 

            if (index==3)
            {
      LayoutInflater inflater = (LayoutInflater) Starttracker.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      popupWindow = new PopupWindow(inflater.inflate(R.layout.popup,null, false),300,100,true);
     // RelativeLayout01 is Main Activity Root Layout
      popupWindow.showAtLocation(findViewById(R.id.relativelayout), Gravity.CENTER, 0,0);

         } else
            {
                Chronometer chrono=(Chronometer)findViewById(R.id.chronometer);
                chrono.start();
            }
        }

        public void onNothingSelected(AdapterView<?> arg0) {}
    });  




}

可以帮助我吗

i want a spinner with items'A','B','C'

if u select 'A' or'B' means the chronometer has to run.

while select the item 'C' the popup window has 2 open with edittext and 'Ok' button..

if you type the'D' in the edittext means that has too add in the spinner while add the chonometer has to run

here is my code:

public class Starttracker extends Activity {

PopupWindow popupWindow;


    String[] Items = {
                "A",
                "B",
                "C",
                "D",

        };

    Spinner s1;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.start);


  s1 = (Spinner) findViewById(R.id.spinner);

    final ArrayAdapter<String> adapter  = new ArrayAdapter<String>(
            this,android.R.layout.simple_spinner_item,Items);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    s1.setAdapter(adapter);
    s1.setOnItemSelectedListener(new OnItemSelectedListener()
    {
        public void onItemSelected(AdapterView<?> arg0, 
        View arg1, int arg2, long arg3) 
        {
            int index = s1.getSelectedItemPosition();
            Toast.makeText(getBaseContext(), 
                "You have selected item : " + Items[index], 
                Toast.LENGTH_SHORT).show(); 

            if (index==3)
            {
      LayoutInflater inflater = (LayoutInflater) Starttracker.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      popupWindow = new PopupWindow(inflater.inflate(R.layout.popup,null, false),300,100,true);
     // RelativeLayout01 is Main Activity Root Layout
      popupWindow.showAtLocation(findViewById(R.id.relativelayout), Gravity.CENTER, 0,0);

         } else
            {
                Chronometer chrono=(Chronometer)findViewById(R.id.chronometer);
                chrono.start();
            }
        }

        public void onNothingSelected(AdapterView<?> arg0) {}
    });  




}

can any help to me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

那支青花 2024-10-25 23:29:59
final String[] items = {"A", "B", "C"};

final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Choose me!");
builder.setItems(items, new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int item) {
        if ("A".equals(items[item]) || "B".equals(items[item])) {
            // run whatever...
        }

        if ("C".equals(items[item])) {
            final EditText edit = new EditText(context);

            final Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("Choose a custom option.");
            builder.setView(edit);
            builder.setPositiveButton("Save", new OnClickListener() {

                public void onClick(final DialogInterface dialog, final int which) {
                    String input = edit.getText().toString();
                    // add input to array, or do whatever.

                    dialog.dismiss();
                }
            });
            builder.create().show();
        }

        dialog.dismiss();
    }
});
builder.create().show();

我没有测试它(直接从我的脑海中写下来),但它应该可以通过一些修改来工作。

祝你好运
汤姆

final String[] items = {"A", "B", "C"};

final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Choose me!");
builder.setItems(items, new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int item) {
        if ("A".equals(items[item]) || "B".equals(items[item])) {
            // run whatever...
        }

        if ("C".equals(items[item])) {
            final EditText edit = new EditText(context);

            final Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("Choose a custom option.");
            builder.setView(edit);
            builder.setPositiveButton("Save", new OnClickListener() {

                public void onClick(final DialogInterface dialog, final int which) {
                    String input = edit.getText().toString();
                    // add input to array, or do whatever.

                    dialog.dismiss();
                }
            });
            builder.create().show();
        }

        dialog.dismiss();
    }
});
builder.create().show();

I didn't test it (written straight from my mind), but it should work with a few modifications.

Good luck
Tom

等往事风中吹 2024-10-25 23:29:59

试试这个代码..
公共类 Starttracker 扩展 Activity {

String[] Items = {
            "A",
            "B",
            "C",
            "D",

    };

Spinner s1;

@Override
公共无效onCreate(捆绑保存实例状态){
super.onCreate(savedInstanceState);
setContentView(R.layout.start);

s1 = (Spinner) findViewById(R.id.spinner);

final ArrayAdapter<String> adapter  = new ArrayAdapter<String>(
        this,android.R.layout.simple_spinner_item,Items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);

}
公共布尔onItemSelected(AdapterView父,视图v,int位置,长id){

 if (((items[position])=="A")||((items[position])=="B")) {

Chronometer chrono =(Chronometer)findViewById(R.id.chronometer);
计时开始();
}
}
//......

            GoodLuck

TRy this code..
public class Starttracker extends Activity {

String[] Items = {
            "A",
            "B",
            "C",
            "D",

    };

Spinner s1;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);

s1 = (Spinner) findViewById(R.id.spinner);

final ArrayAdapter<String> adapter  = new ArrayAdapter<String>(
        this,android.R.layout.simple_spinner_item,Items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);

}
public boolean onItemSelected(AdapterView parent,View v, int position, long id) {

 if (((items[position])=="A")||((items[position])=="B")) {

Chronometer chrono=(Chronometer)findViewById(R.id.chronometer);
chrono.start();
}
}
//.....

            GoodLuck
宫墨修音 2024-10-25 23:29:59

我的问题的答案如下:

{
        int size=tempArray.length;

        for(int i=0;i<size;i++){
            Items.add(tempArray[i]);
}

大家

            if(index==3)
            {
                final Dialog dialog=new Dialog(Starttracker.this);
                dialog.setContentView(R.layout.popup);
                dialog.setTitle("Enter The Item");
                dialog.setCanceledOnTouchOutside(true);

                final EditText filename=(EditText)dialog.findViewById(R.id.filename);
                filename.setText("");

                Button d_ok=(Button)dialog.findViewById(R.id.d_ok);
                Button d_cancel=(Button)dialog.findViewById(R.id.d_cancel);


                d_ok.setOnClickListener(new OnClickListener(){

                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub

                        String textHolder = filename.getText().toString();

                        dialog.dismiss();

                        Items.add(textHolder);

                        //  s1.setAdapter(adapter);

                        // notifyDataSetChanged();

                    }
                });
                d_cancel.setOnTouchListener(new OnTouchListener(){
                    public boolean onTouch(View v,MotionEvent me){
                        dialog.dismiss();
                        return false;
                    }
                });
                dialog.show();

                return;
            }

非常感谢

the answer is following to my question:

{
        int size=tempArray.length;

        for(int i=0;i<size;i++){
            Items.add(tempArray[i]);
}

and

            if(index==3)
            {
                final Dialog dialog=new Dialog(Starttracker.this);
                dialog.setContentView(R.layout.popup);
                dialog.setTitle("Enter The Item");
                dialog.setCanceledOnTouchOutside(true);

                final EditText filename=(EditText)dialog.findViewById(R.id.filename);
                filename.setText("");

                Button d_ok=(Button)dialog.findViewById(R.id.d_ok);
                Button d_cancel=(Button)dialog.findViewById(R.id.d_cancel);


                d_ok.setOnClickListener(new OnClickListener(){

                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub

                        String textHolder = filename.getText().toString();

                        dialog.dismiss();

                        Items.add(textHolder);

                        //  s1.setAdapter(adapter);

                        // notifyDataSetChanged();

                    }
                });
                d_cancel.setOnTouchListener(new OnTouchListener(){
                    public boolean onTouch(View v,MotionEvent me){
                        dialog.dismiss();
                        return false;
                    }
                });
                dialog.show();

                return;
            }

thank a lot to all

时光沙漏 2024-10-25 23:29:59

我的项目的无耻插件。

查看 Android 弹出式旋转视图

Shameless plug for my project.

Check out Android Popup Spinner View

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文