我有一个设置菜单,可以在应用程序的所有屏幕中使用。现在,当我单击菜单并转到特定屏幕编辑进入设置并按回然后我无法知道单击菜单项的屏幕。 我试图将活动名称置于意图中,但这听起来并不是一个好主意。 请帮忙。
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类在我的清单中有一个对话框主题
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
答案 0 :(得分:0)
对于发布答案的延迟表示抱歉。我有问题 使用下面的方法解决了问题。
public void onBackPressed() {
super.onBackPressed();
if(count == 0){
super.onBackPressed();
}else{
for (int i = 0; i < count; i++) {
super.onBackPressed();
}
并且在我单击对话框活动上的“保存”按钮后,我添加了以下代码来更新所选项目的值。而不是使用新意图再次启动活动,我只是将'finish();`称为瓦卡斯建议。
SetProperties.propsList = getProperties();
PropertyAdapter adapter = (PropertyAdapter) SetProperties.listview.getAdapter();
adapter.notifyDataSetChanged();
finish();
感谢大家的帮助和指导:)