Android 中微调器的弹出菜单
我想要一个带有“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我没有测试它(直接从我的脑海中写下来),但它应该可以通过一些修改来工作。
祝你好运
汤姆
I didn't test it (written straight from my mind), but it should work with a few modifications.
Good luck
Tom
试试这个代码..
公共类 Starttracker 扩展 Activity {
@Override
公共无效onCreate(捆绑保存实例状态){
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
s1 = (Spinner) findViewById(R.id.spinner);
}
公共布尔onItemSelected(AdapterView父,视图v,int位置,长id){
Chronometer chrono =(Chronometer)findViewById(R.id.chronometer);
计时开始();
}
}
//......
TRy this code..
public class Starttracker extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
s1 = (Spinner) findViewById(R.id.spinner);
}
public boolean onItemSelected(AdapterView parent,View v, int position, long id) {
Chronometer chrono=(Chronometer)findViewById(R.id.chronometer);
chrono.start();
}
}
//.....
我的问题的答案如下:
大家
非常感谢
the answer is following to my question:
and
thank a lot to all
我的项目的无耻插件。
查看 Android 弹出式旋转视图
Shameless plug for my project.
Check out Android Popup Spinner View