如何在操作菜单工具栏中实施 putExtras SQLite Android

How to Implemanting putExtras SQLite in action menu toolbar Android

我看过很多关于SQLite CRUD 的教程,但大多数都是使用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);
        }      
    }

请问如何在

中实现 putExtras
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();

然后这样写。

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);

希望对您有所帮助。