Dependent dropdown using Exposed Drop-Down Menu and AutoCompleteTextView - java

#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//Define city spinner but we will populate the option through the selected state
policeStationSelectDropdown = findViewById(R.id.psAutoCompleteText);
// Obtain the selected district
selectedDistrict = districtSelectDropdown.getSelectedItem().toString();
Toast.makeText(Complaint_page.this,selectedDistrict, Toast.LENGTH_SHORT).show();
// int parentId = parent.getId();
if (parent.getId() == R.id.districtAutoCompleteText)
getSelectedItem() is showing error??
How to use this with autoCompleteTextView. I want dependent dropdown using Exposed Drop-Down Menu and autoCompleteTextView using JAVA.

Related

Spinner Item re-selected

I am implementing a spinner with auto fill text view and adding same list in adapter of Spinner and auto fill text view,
If I select a item from spinner it will be set in autoFillTextView,
But the problem is if I select a item from spinner and then make a change in autofillTextView, and then again select same item from spinner then controller is not going back to spinner onSelected method,
Thanks in advance.
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (parent.getId()) {
case R.id.spinnerGroupName:
actvMatchGroup.setText("");
//Your Another Action Here.
for (int i = 0; i < groupList.size(); i++) {
if (groupName[position] == groupList.get(i).getGroupName()) {
groupId = Integer.parseInt(groupList.get(i).getGroupId());
group_id = groupId;
}
}
tvMatchGroup.setText(groupName[position]);
actvMatchGroup.setText(groupName[position]);
break;
}

Why I can't click on an element in a ListView of AndroidStudio for selected it and use for showing other data in a new Activity?

I have to select a row of a list which is a ListView of Android studio for take it and show in a new Activity the data of this object. But i can't
physically click on the row of the list so this are not selected and the action for view the new activity dont start. Please can someone help me? Thanks
this.listaCorrieri.setOnItemClickListener(Applicazione.getInstance().getControlloPrincipale().getAzioneSelezionaCorriere());
private class AzioneSelezionaPietanza implements ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ActivityPrincipale activityPrincipale = (ActivityPrincipale) Applicazione.getInstance().getCurrentActivity();
List<Pietanza> listaPietanzeCategoria = (List<Pietanza>) Applicazione.getInstance().getModello().getBean(Costanti.LISTA_PIETANZE_PER_CATEGORIA);
Pietanza pietanzaSelezionata = listaPietanzeCategoria.get(position);
Applicazione.getInstance().getModello().putBean(Costanti.PIETANZA_SELEZIONATA, pietanzaSelezionata);
Archivio archivio = (Archivio) Applicazione.getInstance().getModello().getBean(Costanti.ARCHIVIO);
Pietanza pietanzaSimile = archivio.cercaPietanzaSimile(pietanzaSelezionata);
activityPrincipale.mostraPietanzaSimile();
}
}

Deselect current list view item if selected again

I currently have a list view in which you can select an item and it will highlight the currently selected item. But I would like to set it sot that so that if the user clicks on the same item currently selected in the list again it will unhighlight the list item and have no list item currently selected/
currentUsersCameras.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(final AdapterView<?> parent, View view, final int position, long id) {
for (int i = 0; i < parent.getChildCount(); i++) {
parent.getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
view.setBackgroundColor(Color.rgb(3, 169, 244));
}
}
});
Listview/Recyclerview items requires you to handle if and else cases always. So if you want to do something for one item and not for another item, and similarly if you want to do and undo the same thing to the same item, handle both IF and ELSE

How to get the value of a TextView that is part of a ListView row in all checked items

As illustrated in the photo, i have a list view that is made up of a custom layout which has two TextView. One TextView is for storing numbers which has a visibility of gone, the other is for storing the name, which is visible.
all i want is to be able to get a string of all numbers that are selected when the send button is clicked.
A good suggestion here is to use a recyclerview instead of list view.
To achieve want you want with a list view you just set an item click listener to your list view in your activity. The item click listener will pass the View which is the current cell in the list view. Then you can find textview by id to locate. The Textview ID is set in the layout xml.
Example
listView.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View cell,int pos, long arg1)
{
TextView textView = (TextView)cell.findViewByID(R.id.myTextView);
String texViewContents = textView.getText().toString();
}
});

how to set id for each item in ListView

When I retrieve data from database, I have for each row unique ID I want match id with string in listview but ID I want it to be invisible, so that when i click any item in listview trans me to another activity have data about this item.
That means I have Two table in database match together I want to retrieve one as listview , when click item trans me to data match the item i have been clicked.one as listview , when click item trans me to data match the item i have been clicked.
How can I do this?
this should work
myAdapter.setViewBinder(new MyViewBinder());
public class MyViewBinder implements ViewBinder {
#Override
public boolean setViewValue(View view, Object data, String text){
//Since it iterates through all the views of the item, change accordingly
if(view instanceof TextView){
((TextView)view).setTag("whatever you want");
}
}
}
You can use custom adapter and use like this method to achive yor goal
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if(vi == null){
vi = inflater.inflate(R.layout.row_layout, null);
}
final int id = idGetFuncttion(position);
vi.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
doSomethingWithID(id);
}
});
return vi;
}
1.set your unique id to each row by setTag property and retrieve it by getTag property
2.use custom adapter and custom listview layout for the listview and set your unique id to invisible textview in custom listview layout through custom adapter

Categories