I think that through the Bundle, but not quite familiar with its implementation. I would be grateful for any help.

MainActivity - from where we are passing

package com.genius.project.passwordhelper; import android.app.DialogFragment; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.os.AsyncTask; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.widget.AdapterView; import android.widget.CursorAdapter; import android.widget.ListView; import android.widget.SimpleCursorAdapter; import android.widget.Toast; import java.util.Arrays; public class MainActivity extends AppCompatActivity { private SQLiteDatabase dataBaseMain; private Cursor displayMainCursor; SQLiteOpenHelper dbHelper; DialogFragment dialogAddPass; ListView listViewPasswords; FloatingActionButton fab; public Bundle tempBundle; public void updateMainList() { //Ρ‡Π΅Ρ€Π΅Π· SimpleCursorAdapter - ΠΎΠΏΡ‚ΠΈΠΌΠ°Π»ΡŒΠ½Π°Ρ Ρ€Π°Π±ΠΎΡ‚Π° (?) listViewPasswords = (ListView) findViewById(R.id.listPasswords); try{ dbHelper = new PasswordDatabaseHelper(this); dataBaseMain = dbHelper.getReadableDatabase(); displayMainCursor = dataBaseMain.query("DATAPASS", new String[]{"_id", "SITE"}, null, null, null, null, null); CursorAdapter cusrorDisplay = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, displayMainCursor, new String[]{"SITE"}, new int[]{android.R.id.text1}, 0); listViewPasswords.setAdapter(cusrorDisplay); } catch(SQLiteException e) { Snackbar.make(fab, R.string.database_error, Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); dialogAddPass = new CustomDialogFragment(); //ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡƒΠ΅ΠΌ Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚ AddPass fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialogAddPass.show(getFragmentManager(), "enterPass"); } }); updateMainList(); listViewPasswords.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> listView, View v, int position, long id) { //Π±Ρ€Π°Ρ‚ΡŒ Position для ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ Π½ΠΎΠΌΠ΅Ρ€Π° пароля! DialogFragment dialogShowPass = new DetailedPassFragment(); //ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΡƒΠ΅ΠΌ Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚ ShowPass backDb backTask = new backDb(); //запуск асинхронного класса поиска пароля ΠΈ ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‡Π° Π΅Π³ΠΎ Π² Bundle воспроизводимому Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚Ρƒ backTask.execute(position); dialogShowPass.setArguments(tempBundle); dialogShowPass.show(getFragmentManager(), "editPass"); } }); listViewPasswords.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> arg0, View v, int index, long arg3) { Toast.makeText(MainActivity.this,listViewPasswords.getItemAtPosition(index).toString(), Toast.LENGTH_LONG).show(); return false; } }); } class backDb extends AsyncTask<Integer, Void, Bundle> { //Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ курсор для поиска Π·Π½Π°Ρ‡Π΅Π½ΠΈΠΉ, Π²Ρ‹Π΄Π°Π½Π½ΠΎΠ³ΠΎ ΠΊΠ½ΠΎΠΏΠΊΠΎΠΉ editPass Π² ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΉ ΠΏΠΎΡ‚ΠΎΠΌ String site; String pass; String info; String[] out; String debugInfo; //DB @Override protected Bundle doInBackground(Integer... id) { debugInfo = String.valueOf(id.length); //DB PasswordDatabaseHelper helper = new PasswordDatabaseHelper(MainActivity.this); SQLiteDatabase dbShowPass = helper.getReadableDatabase(); Cursor cursorShowPass = dbShowPass.query("DATAPASS", new String[]{"SITE", "PASS", "INFO"}, "_id = ?", new String[]{Arrays.toString(id)}, null, null, null); if(cursorShowPass.moveToFirst()) { tempBundle = new Bundle(); tempBundle.putString("site", cursorShowPass.getString(0)); tempBundle.putString("pass", cursorShowPass.getString(1)); tempBundle.putString("info", cursorShowPass.getString(2)); return tempBundle; } else { dbShowPass.close(); cursorShowPass.close(); return tempBundle = new Bundle(); } } @Override protected void onPostExecute(Bundle result) { if(!result.isEmpty()) { Toast.makeText(MainActivity.this, "Data send into Bundle"+" "+debugInfo+" "+out[0], Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, "Data NOT send"+" "+debugInfo+" "+out[0], Toast.LENGTH_SHORT).show(); } } } @Override public boolean onCreateOptionsMenu(Menu menu) { //созданиС списка мСню // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { //ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ списка мСню // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { Intent intentSettings = new Intent(MainActivity.this, SettingsActivity.class); startActivity(intentSettings); return true; } return super.onOptionsItemSelected(item); } @Override public void onResume() { super.onResume(); Snackbar.make(fab, R.string.dataUpdated, Snackbar.LENGTH_LONG) .setAction("Action", null).show(); updateMainList(); } @Override public void onDestroy() { super.onDestroy(); dataBaseMain.close(); displayMainCursor.close(); } } 

DetailedPassFragment - where to send

 package com.genius.project.passwordhelper; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.widget.Toast; public class DetailedPassFragment extends DialogFragment implements DialogInterface.OnClickListener { EditText siteForm; EditText passForm; EditText infoForm; Bundle inputBundle; @Override public void onClick(DialogInterface dialogInterface, int buttonId) { Dialog editForm = (Dialog) dialogInterface; switch (buttonId) { case(Dialog.BUTTON_POSITIVE): { editForm.dismiss(); break; } case(Dialog.BUTTON_NEGATIVE): { editForm.dismiss(); break; } } } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { View detailedForm = getActivity().getLayoutInflater().inflate(R.layout.passdetail, null); siteForm = (EditText) detailedForm.findViewById(R.id.site); //Ρ€Π°Π±ΠΎΡ‚Π° с Π΄Π°Π½Π½Ρ‹ΠΌΠΈ Π² EditText Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² onCreateDialog passForm = (EditText) detailedForm.findViewById(R.id.pass); infoForm = (EditText) detailedForm.findViewById(R.id.info); inputBundle = getArguments(); siteForm.setText(inputBundle.getString("site")); passForm.setText(inputBundle.getString("pass")); infoForm.setText(inputBundle.getString("info")); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) .setTitle(R.string.editPassLayer) .setView(detailedForm) .setPositiveButton(R.string.deleteItem, this) .setNegativeButton(R.string.enterPass_button, this); return builder.create(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return getActivity().getLayoutInflater().inflate(R.layout.passdetail, null); } @Override public void onStop() { //обновляСт прСдставлСниС mainActivity super.onStop(); MainActivity main = (MainActivity)getActivity(); main.updateMainList(); } /*@Override public void onDestroy() { super.onDestroy(); }*/ } 

    1 answer 1

    You enter the dialogShowPass.setArguments(tempBundle); into the dialog dialogShowPass.setArguments(tempBundle); This is where you put the necessary data, and in the dialog make this.getArguments()

    • Hmm, but do not tell me why when you start the program, during the operation of the code from MainActivity, when you first click on the list item (and the asynchronous process is triggered, it is always passed to the first null result?
    • one
      null because you start the stream and move on. At the time of calling the dialogShowPass.setArguments(tempBundle) method, the dialogShowPass.setArguments(tempBundle) object tempBundle not exist yet - pavel163