Я создал диалоговое окно оповещения. Он открывает настраиваемое представление, которое имеет просмотр списка и поиск. Мне нужно обновить представление, открывшее этот настраиваемый диалог. Как я могу это сделать?
Что я имею в виду, могу ли я получить представление, с помощью которого открылось другое представление? Я хочу получить представление, которое открыло другое представление.
это мой код:
public class activitySignUp extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemClickListener, SearchView.OnQueryTextListener, SearchView.OnSuggestionListener {
// For Custom Views...
private ListView listView;
// for Different Methods...
private ArrayList < ? > GeneralList;
private ArrayAdapter < ? > GeneralAdapter;
private SearchView searchView;
// Popup view for Selection...
private AlertDialog builder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
initView();
}
// Inside context i am passing the context of the view according to switchview...
// intentRelatedTasks are for Passing intents...
// For showing error there's show Error...
builder = new AlertDialog.Builder(activitySignUp.this).create();
View custom_view = LayoutInflater.from(activitySignUp.this).inflate(R.layout.popup_view,
null);
searchView = custom_view.findViewById(R.id.search_bar);
listView = custom_view.findViewById(R.id.list_all);
searchView.setIconifiedByDefault(false);
searchView.requestFocus();
builder.setView(custom_view);
// Initializing ArrayLists and Setting them up on Adapters...
GeneralList = new ArrayList < > ();
GeneralAdapter = new ArrayAdapter < > (activitySignUp.this, android.R.layout
.simple_list_item_1, GeneralList);
listView.setAdapter(GeneralAdapter);
listView.setOnItemClickListener(this);
searchView.setOnQueryTextListener(this);
searchView.setOnSuggestionListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.stateInput:
// This is the view from which i am opening up alertdialog, i have plenty of these(TextViews) with different IDs,which opens up same AlertDialog with different listitems... So i want this view to be updated when i open up/ Dismiss alertview...
getStates();
break;
}
}
private void getStates() {
MyAPI.getStates(new Callback < BasicResponse > () {
@Override
public void onResponse(Call < BasicResponse > call, Response < BasicResponse > response) {
Log.i(TAG, "GetStates");
Log.i(TAG, String.valueOf(response.isSuccessful()));
Log.i(TAG, GsonUtils.toGson(response.body()));
if (response.isSuccessful() && response.isSuccessful()) {
builder.setTitle(getResources().getString(R.string.select_state));
BasicResponse basicResponse = response.body();
String res = basicResponse.getResponse();
Type listType = new TypeToken < ArrayList < State >> () {}.getType();
ArrayList list = GsonUtils.fromGson(res, listType);
ArrayList arrayList = updateListAndDropdown(GeneralList, list, GeneralAdapter);
Log.d(TAG, "onResponse: " + arrayList);
UpdateTextViewUI(getResources().getString(R.string.select_state), stateInput);
builder.show();
}
}
@Override
public void onFailure(Call < BasicResponse > call, Throwable t) {
Log.i(TAG, t.getMessage());
}
});
}
private ArrayList updateListAndDropdown(ArrayList arrayList, ArrayList arrayList_new, ArrayAdapter arrayAdapter) {
Log.d(TAG, "updateListAndDropdown: " + arrayList_new);
arrayList.clear();
if (arrayList_new != null)
arrayList.addAll(arrayList_new);
arrayAdapter.notifyDataSetChanged();
return arrayList;
}
// This is where i want things to happen. on click i want to update UI which has opened up my alertdialog.
@Override
public void onItemClick(AdapterView << ? > adapterView, View view, int position, long l) {
ViewParent parent = adapterView.getParent();
AppCompatTextView appCompatTextView = (AppCompatTextView) parent;
appCompatTextView.setText(GeneralList.get(position).toString());
builder.dismiss();
}
}