List item having button - android

I am working on Android application.
I have a ListView. One of the item has a button, and others have simple text views. I have now requirement of showing button as pressed when it is pressed. I am able to do this.But when I connect the device via. Bluetooth keyboard and navigate through the list. I see list items being selected as expected.But I want the item with the button to look as if button has been selected (focused).
Thanks
Krishna

use
list.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});

Related

Can you help me with a listener?

I have a function of showDiaglog.
I just want to, when user tap checkbox the diaglog shown, and the spinner also, but I got a problem with listener. Everytime I open settings, the popup show up twice.
First because of listener of spinner then second because one of my setting checked.
I save every changes in that setting.
Can you help me?
selectLanguage
.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0,
View arg1, int position, long arg3) {
// TODO Auto-generated method stub
saveSettingan(Key_Select, position);
if (position == 0) {
setDefaultLocal();
} else {
setLocal("in");
}
showDialog();
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
and this one
case R.id.checkAcak:
saveSettingan(Key_Acak, isChecked);
showDialog();
break;
You could store a boolean which remembers the visibility of the dialog. Your show dialog should include this:
if (isDialogVisible)
return;
isDialogVisible = true;
Then you set a dismiss listener to set isDialogVisible to false.

spinner android set selection alternative

I created 2 Spinners and I filled them with an array of numbers. What I want is that the user chooses the number they want on the first one, and then I save it to a variable that I use to populate the dropdown list of the second one with values that start after that number. How can I do this? How can I change the text in the second spinner to start with the number chosen.
I have this, I store the item of the Spinner on the variable x, and I want a second Spinner to start with that variable.
mySpinner.setAdapter(new ArrayAdapter<String>(NewGuiaActivity.this, android.R.layout.simple_spinner_dropdown_item,
establist));
// Spinner on item click listener
mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
// TODO Auto-generated method stub
// Locate the textviews in activity_main.xml
arg0.setSelection(5);
x = estab.get(position).getID();
Toast.makeText(getApplicationContext(), x, Toast.LENGTH_LONG).show();
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
the arg0.setSelection(5), does the trick but it dont let me choose another value when i click on a diferent item of the spinner how can i change this.

After item clicked in spinner, Display dialog

Is it possible to have a spinner that displays a dialog when a item is pressed in the list
and is it good code and not too messy. If so could someone show me some code so i can see the make up of this done thank you
You can add an item selected listener on your spinner and then while an item is selected or touched start a dialog. like this --
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Here add the Dialog you want !", Toast.LENGTH_SHORT).show();
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});

How to handle an onClickListener for a Button within the Spinner onItemSelected(...) method?

I have a Spinner.onItemSelected() method and I want to be able to have an event happen once a Button is clicked after selecting the Spinner item.
For example if you select Beginner for your Spinner and click Java for another spinner. Under that I have a button that says Start. How do I have a Button.onClick event correspond with the selected spinner options?
I did something like this but what I assigned as the setOnClickListener() value is not being read by the View.OnClickListener.
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
selected = (Integer) arg0.getItemAtPosition(0);
position = spinner.getSelectedItemPosition();
start = (Button)findViewById(R.id.start);
start.setOnClickListener(phaseHandler);
View.OnClickListener phaseHandler = new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
};
}
The phaseHandler I declared is not being read by start.setOnClickListener(phaseHandler) so this results in my View.OnCLickListenr invocation not working because phaseHandler is not being set to the Button start. In Eclipse my phaseHandler has the red underlining curly for an error where it says start.setOnClickListener(phaseHandler);
Any Ideas?
move start.setOnClickListener(phaseHandler); down
this may help you
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
selected = (Integer) arg0.getItemAtPosition(0);
position = spinner.getSelectedItemPosition();
start = (Button)findViewById(R.id.start);
View.OnClickListener phaseHandler = new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
};
start.setOnClickListener(phaseHandler);
}

Can i get onClickListener for this list listed by CustomAdapter?

I have listed a list with custom adapter to display different images in each list item and succeeded.
Now i need to add a onitemclick listener for that list.
Unable to access the id because the list id is - "#+id/android:list".
Unable to identify this id.
Any ideas please share.
You will get some more idea when you see this below link
Click here for the example i tried.
In the given example, the ListActivity is extended in CustomAdapterActivity.java
so its simple to get Click events of the list items by writing list item click listener
and to write onClickListener you need to do
like this in that class.
**
public class Test extends ListActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
ListView lv = getListView();
lv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
}
}
**
And To Know More and Learn About LIST VIEW in Android you can view this : http://www.vogella.de/articles/AndroidListView/article.html#overview_listview

Categories

Resources