i have a following ListActivity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get Strings from res/strings.xml
String items[] = { getString(R.string.mainMenu_1),
getString(R.string.mainMenu_2), getString(R.string.mainMenu_3),
getString(R.string.mainMenu_4), getString(R.string.mainMenu_5)};
strings = items;
ListAdapter listAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, items);
setListAdapter(listAdapter);
}
Displaying it and reacting to user clicks works great, now I want to add some pictures before the text (like "Settings").
can someone explain me how to do this?
(How to get pictures from res/drawable isn needed to get explained ;-))
greets,
poeschlorn
You have to make your own ListAdapter. Here's a fine tutorial about this: http://www.anddev.org/novice-tutorials-f8/iconified-textlist-the-making-of-t97.html?sid=57c1096099cb666b386eb4ab65aba0c6
Related
Is it possible to provide values to the AutoCompleteTextView in XML / via resources, therefore without setting an adapter in code?
I want to use the AutoCompleteTextView as part of an exposed dropdown menu, so all values shall be shown at once and no filtering shall happen. Also all values to be shown are known at compile time.
I think you can do that by using the list via Resource and implementing it in AutoCompleteTextView passing by the adapter.
See the example here :
public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
Resources res = getResources();
private static final String[] COUNTRIES = res.getStringArray(R.array.planets_array);
}
Hope this could help you or any one else .
Yes its possible. There is a method showDropDown() which you can call.
Try something like
autoCompleteTextView.showDropDown()
Reference :
https://developer.android.com/reference/android/widget/AutoCompleteTextView.html#showDropDown()
I would like to add two buttons in my listview.
Two button edit and delete for my list.
I have already traveled the other posts on this subject but I still can not :(.
I have already created a custom listview.
I am a beginner so I have a hard time understanding.
This would be nice a little help.
Here is my code
My current listview
public class liste_offre extends AppCompatActivity {
DatabaseHelper myDb;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.liste_offre);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ListView listView = (ListView) findViewById(R.id.List_offre);
myDb = new DatabaseHelper(this);
ArrayList<String> theList = new ArrayList<>();
Cursor res = myDb.getAllData();
if (res.getCount()==0){
Toast.makeText(liste_offre.this,"Liste vide",Toast.LENGTH_LONG).show();
}else {
while (res.moveToNext()){
theList.add(res.getString(1));
ListAdapter listAdapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,theList);
listView.setAdapter(listAdapter);
}
}
}
}
Please refer the below post it may be exactly what you want
ListView with Add and Delete Buttons in each Row in android
Hope this helps you.
I am just now learning about how listViews work. I currently have a ListView in which each row is an image, with two TextViews to its right. The top TextView is larger and contains a name, the bottom one is smaller and contains a surname. I currently have an ArrayAdapter set up properly to populate the names. However, I can't quite figure out how to also populate the surnames, as doing the same exact thing seems to not work. My code currently looks like this. The k ListView is the one I'm trying to implement for surnames. This is obviously an incorrect approach, though. If I run that code, it will no longer show the names, but only the surnames.
ListView l;
ListView k;
String[] names = {"Andrew","Billy","Charlie","Daniel","Eric","Frank","George","Hal"};
String[] surNames = {"Ainbinder","Brenton","Chen","Donovan","Epstein","Ferris","Gallivan","Higgins"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
l = (ListView) findViewById(R.id.listView1);
k = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.single_row, R.id.topLine, names);
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this, R.layout.single_row, R.id.secondLine, surNames);
l.setAdapter(adapter);
k.setAdapter(adapter2);
l.setOnItemClickListener(this);
}
The way you are implementing is not correct. You can follow the link below for correct implementation:
Multiple TextViews in the same List Item
I am just starting out using Android, so this is probably a very basic question.
I have created an array called priorityNames. I want to display that in a list and be able to make a selection from that list. At this stage, I cannot get the list to display.
As a starting point I used a short example from windrealm.org tutorials
Any help would be appreciated. Also if anyone can point me to a better example it would be appreciated.
public class SimpleListViewActivity extends Activity {
private ListView mainListView ;
private ArrayAdapter<String> listAdapter ;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Find the ListView resource.
mainListView = (ListView) findViewById( R.id.mainListView );
listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, R.array.priorityNames);
mainListView.setAdapter(listAdapter);
}
}
You are passing just an id with R.array.priorityNames.
Use:
getResources().getStringArray(R.array.priorityNames)
You are probably missing a TextView in your xml layout (simplerow.xml) with id:
...android:id="#android:id/text1"...
My senior project group is developing an android application and we would like to be able to implement something like the example found in this screenshot:
What we have right now is a Spinner drop down, the very first default will be "Add faculty...". Once you create that faculty, it will be selectable in the spinner, but in case a class has more than one faculty(ie: Professor, Teaching Assistant), we want to be able to add more than one spinner using the +/- buttons like you see here.
Any examples or leads in the right direction would be most appreciated.
Create two variable of ArrayAdapter and Arraylist of string to be global.
ArrayList<String> art;
ArrayAdapter<String> adapter;
And then in onCreate initialize the spinner as below
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
s1 = (Spinner) findViewById(R.id.spinner);
art=new ArrayList<String>();
art.add("professer");
adapter = new ArrayAdapter<String>(
this,android.R.layout.simple_spinner_item,art);//Items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
}
And then in button click , add new elements in array and notify the adapter
public void btn_click(View v)
{
art.add("Technical Assistant");
adapter.notifyDataSetChanged();
}