我想要一个带有'A','B','C'
项目的微调器如果您选择'A'或'B'表示计时器必须运行。
当选择项目'C'时,弹出窗口打开2,带有edittext和'Ok'按钮..
如果你在edittext中输入'D'意味着在添加测量计时添加了微调器则必须运行
这是我的代码:
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) {}
});
}
对我有任何帮助
答案 0 :(得分:3)
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();
我没有测试它(直接写在我的脑海里),但它应该有一些修改。
祝你好运 汤姆答案 1 :(得分:1)
尝试此代码.. 公共类Starttracker扩展了Activity {
String[] Items = {
"A",
"B",
"C",
"D",
};
Spinner s1;
@覆盖 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
答案 2 :(得分:0)
答案在于我的问题:
{
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;
}
非常感谢
答案 3 :(得分:0)
我项目的无耻插件。