0
我有一个设置菜单,用于应用程序的所有屏幕。现在,当我点击菜单并转到特定的屏幕编辑来设置,然后按回来,然后我无法知道从哪个屏幕菜单项被点击。 我试图把活动名称的意图,但它听起来不像是个好主意.. 请帮助。从菜单返回按下
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.propsmain);
setTitle("Settings");
prev_screen = getIntent().getStringExtra("prev_screen");
try {
final ArrayList<Properties> propsList = getProperties();
if (propsList == null || propsList.size() == 0) {
// show alert
} else {
setListAdapter(new PropertyAdapter(this, R.layout.props,
propsList));
}
final ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
// @Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Properties prop = propsList.get(arg2);
Bundle b = new Bundle();
b.putString("prop_name", prop.getName());
b.putString("prop_value", prop.getValue());
Intent intent = new Intent(SetProperties.this,
EditPropertyActivity.class);
intent.putExtras(b);
startActivity(intent);
}
});
} catch (PropertyFileMissing e) {
AlertDialog dialog = new AlertDialog.Builder(SetProperties.this)
.create();
dialog.setTitle("Failure");
dialog.setMessage(e.toString());
dialog.setIcon(R.drawable.error);
dialog.setButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.show();
}
}
// EditProperty类这有dialogtheme在我的清单
ublic class EditPropertyActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog);
setTitle("");
TextView propName = (TextView) findViewById(R.id.tv_propName);
final String tagName = getIntent().getExtras().getString("prop_name");
final String value = getIntent().getExtras().getString("prop_value");
propName.setText(getIntent().getExtras().getString("prop_label"));
final EditText ed_propValue = (EditText) findViewById(R.id.ed_propValue);
ed_propValue.setText(value);
if (tagName.equals("timeout")) {
ed_propValue.setInputType(InputType.TYPE_CLASS_NUMBER);
}
Button btn_save = (Button) findViewById(R.id.btn_save);
btn_save.setOnClickListener(new View.OnClickListener() {
// @Override
public void onClick(View v) {
String newValue = ed_propValue.getText().toString().trim();
if ((tagName.equals("timeout") || tagName.equals("serverUrl") || tagName
.equals("channelName")) && (newValue.equals(""))) {
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.NOT_NULL),
Toast.LENGTH_LONG).show();
return;
}
editFile(tagName, newValue);
finish();
}
});
Button btn_cancel = (Button) findViewById(R.id.btn_cancel);
btn_cancel.setOnClickListener(new View.OnClickListener() {
// @Override
public void onClick(View v) {
finish();
}
});
}
}
--Abhilasha
你为什么不干脆叫'完成();'当推压回去?这样做会导致从堆栈 – waqaslam
返回一个活动对不起,我应该在我的问题中添加这个。我的菜单有一个选项设置,当我点击它时,它会打开一个列表视图,现在点击一个项目就会打开一个对话框来编辑该项目。所以,上面给出的解决方案,即调用finish()不起作用,如果我编辑像3到4个项目。在这种情况下,当我按回它只是回到我的设置屏幕只有我不想要的。 – Abhilasha
目前我传递的活动名称从中点击菜单,并在我的设置活动中,我根据名称调用活动....很多如果其他语句.. :(它工作绝对好..但我想知道有没有其他的方法可以做到这一点... – Abhilasha