我已经阅读了很多关于CRUD SQLite的教程,但是大多数都使用Cursor来获取值数据,使用Button来调用EditScreen。有人告诉我如何在我的编辑菜单工具栏中实现i.putExtras吗?我想在EditText表单中再次显示我的数据。
public class DetailStaffActivity extends AppCompatActivity {
private DBHandler dbHandler;
private TextView txt_resultnomor, txt_resultnama, txt_resulttempatlahir, txt_resulttanggallahir;
private List<Staff> staffList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.staff_details);
dbHandler = new DBHandler(this);
//ambil data
Intent i=getIntent();
final String nomor=i.getExtras().getString("nomor");
final String nama=i.getExtras().getString("nama");
final String tempatlahir = i.getExtras().getString("tempat_lahir");
final String tanggallahir=i.getExtras().getString("tanggal_lahir");
//inisialisasi dulu
txt_resultnomor = (TextView) findViewById(R.id.txt_resultnomor);
txt_resultnama = (TextView) findViewById(R.id.txt_resultnama);
txt_resulttempatlahir = (TextView) findViewById(R.id.txt_resulttempatlahir);
txt_resulttanggallahir = (TextView) findViewById(R.id.txt_resulttanggallahir);
//set inisial dengan data yang telah diambil di dengan intent
txt_resultnomor.setText(nomor);
txt_resultnama.setText(nama);
txt_resulttempatlahir.setText(tempatlahir);
txt_resulttanggallahir.setText(tanggallahir);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_detail, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_edit) {
public void onItemClick(View view, int position) { //here, error when set position in this menu//
// TODO Handle item click
Intent in = new Intent(this, UpdateStaffActivity.class);
Staff staff = staffList.get(position);
String getNama = staffList.get(position).getNama();
in.putExtra("nama", getNama);
startActivity(in);
return true;
}
if (id == R.id.action_delete) {
return true;
}
if (id == R.id.action_settings) {
// Intent i = new Intent(this, About.class);
//startActivity(i);
}
return super.onOptionsItemSelected(item);
}
}
请问,如何在
中实现putExtrasif (id == R.id.action_edit) { }
在此菜单中设置位置时出错。感谢。
答案 0 :(得分:0)
只需删除此行
即可 public void onItemClick(View view, int position) { //here, error when set position in this menu//
// TODO Handle item click
Intent in = new Intent(this, UpdateStaffActivity.class);
Staff staff = staffList.get(position);
String getNama = staffList.get(position).getNama();
这样写。
if (id == R.id.action_edit) {
Intent in = new Intent(this, UpdateMuriddActivity.class);
in.putExtra("nomor", txt_resultnomor.getText().toString());
in.putExtra("nama", txt_resultnama.getText().toString());
in.putExtra("tempat_lahir", txt_resulttempatlahir.getText().toString());
startActivity(in);
希望得到它的帮助。