Я пытаюсь вызвать метод внутри другого класса, который будет заполнять TextViews при щелчке элемента внутри AutoCompleteTextView, который также находится внутри AlertDialogInput.
Но мое приложение падает, когда я щелкаю элемент.
Я новичок в разработке android, поэтому любая помощь будет весьма признательна.
Диалог настраиваемого оповещения Класс диалогового окна оповещения
public static class ToPrintAccountSearchDialog extends AppCompatDialogFragment
{
private AutoCompleteTextView toprint_auto_account_search_dialog;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater layoutInflater = getActivity().getLayoutInflater();
View view = layoutInflater.inflate(R.layout.for_printing_account_search_dialog_layout, null);
builder.setView(view);
builder.setTitle("Search Account");
List<ForBillPrintConsumerEntities> forBillPrintConsumerEntities = new ArrayList<>();
toprint_auto_account_search_dialog = view.findViewById(R.id.Alert_Dialog_Account_Auto_Search);
ForPrintingConsumerAccountSearchAdapter forPrintingConsumerAccountSearchAdapter = new ForPrintingConsumerAccountSearchAdapter(getActivity(), forBillPrintConsumerEntities);
toprint_auto_account_search_dialog.setThreshold(1);
toprint_auto_account_search_dialog.setAdapter(forPrintingConsumerAccountSearchAdapter);
toprint_auto_account_search_dialog.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
{
PrintBill printBill = new PrintBill();
printBill.getotherinformationbyaccountforprinting();
}
});
return builder.create();
}
}
Это код для отображения AlertDialogInput Основная активность
Account_No = findViewById(R.id.toprint_Account_No_Value);
Account_No.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
forPrintAccountSearchDialog();
}
});
public void forPrintAccountSearchDialog()
{
ToPrintAccountSearchDialog toPrintAccountSearchDialog = new ToPrintAccountSearchDialog();
toPrintAccountSearchDialog.show(getSupportFragmentManager(), "ToPrintAccountSearchDialog");
}
это метод, который я хочу вызвать, когда щелчок по элементу внутри AlertDialog AutocompleteTextview, который также находится внутри основного действия, чтобы заполнить мое текстовое представление в основной деятельности
public void getotherinformationbyaccountforprinting()
{
ConsumerAccountForPrinting = toprint_auto_account_search_dialog.getText().toString();
db = new DatabaseHelper(getApplicationContext());
sqLiteDatabase = db.getReadableDatabase();
Cursor cursor = db.ForPrintingGetOtherInfoByAccount(ConsumerAccountForPrinting, sqLiteDatabase);
if (cursor.moveToFirst()) {
do {
String ACCOUNT_NUMBER = cursor.getString(0);
String NAME = cursor.getString(1);
String ADDRESS = cursor.getString(2);
Account_No.setText(ACCOUNT_NUMBER);
Name.setText(NAME);
Address.setText(ADDRESS);
}
while (cursor.moveToNext());
}
}
Помощник базы данных
public Cursor ForPrintingGetOtherInfoByAccount(String keyword, SQLiteDatabase sqLiteDatabase)
{
String [] projections = {ForPrintingConsumerOtherInfoAdapterByAccount.getOtherInfoForPrintingByAccount.ACCOUNT_NO,
ForPrintingConsumerOtherInfoAdapterByAccount.getOtherInfoForPrintingByAccount.NAME,
ForPrintingConsumerOtherInfoAdapterByAccount.getOtherInfoForPrintingByAccount.ADDRESS,
String selection = ConsumerListOtherInfoAdapterByAccount.getOtherInfoForListByAccount.CONSUMER_ACCOUNT_NO+" LIKE ?";
String [] selection_args = {keyword};
Cursor cursor = sqLiteDatabase.query(ForPrintingConsumerOtherInfoAdapterByAccount.getOtherInfoForPrintingByAccount.TABLE_NAME,projections,selection,selection_args,null,null,null);
return cursor;
}
проекция, которая вызывает внутри базы данных помощник
public class ForPrintingConsumerOtherInfoAdapterByAccount
{
public static abstract class getOtherInfoForPrintingByAccount
{
public static final String TABLE_NAME = "toPrintBill";
public static final String ACCOUNT_NO = "account_no";
public static final String NAME = "name";
public static final String ADDRESS = "address";
}
}
Когда я нажимаю диалог оповещения о просмотре текста Выскакивает
* 105 1 * Когда я набираю число Autocompletetextview предложит данные, которые имеют то же значение из таблицы базы данных sqlite
Но когда я щелкните элемент, который происходит
java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.AutoCompleteTextView.getText()' on a null object reference
at com.vicjames.qiimeterreader.PrintBill.getotherinformationbyaccountforprinting(PrintBill.java:224)
at com.vicjames.qiimeterreader.PrintBill$ToPrintAccountSearchDialog$1.onItemClick(PrintBill.java:189)
at android.widget.AutoCompleteTextView.performCompletion(AutoCompleteTextView.java:1017)
Как создать связь между классом диалогового окна оповещений и основным действием, чтобы я мог использовать этот метод?