android-listview

Getting data from Listview with BaseAdapter

不打扰是莪最后的温柔 提交于 2019-12-23 02:18:25
问题 I've an activity(A) that has a Button and when the user press it, it will add an Object to static List . I've another activity(B) that has a ListView to show the content of the static list. In the activity(B) I want to use the attribute of an object that is stored in that static list in the specific row. How can I do that? My code is shown below: //Activity (A): Send.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ... // Add to mycaseList All_Static.MyCaseList

context parameter for custom adapter - getApplicationContext() fails but 'this' works

天涯浪子 提交于 2019-12-23 02:04:26
问题 I have simple code snippet to implement custom list view. In this code, I have CustomAdapter class which extends ArrayAdapter : CustomAdapter adapter = new CustomerAdapter(getApplicationContext(),R.layout.listview_item_row, weather_data); The constructor of CustomAdapter is as below: public CustomerAdapter(Context context, int layoutResourceId, weather[] data) { super(context, layoutResourceId, data); mlayoutResourceId = layoutResourceId; mcontext = context; mdata = data; } If I write this,

context parameter for custom adapter - getApplicationContext() fails but 'this' works

亡梦爱人 提交于 2019-12-23 02:04:15
问题 I have simple code snippet to implement custom list view. In this code, I have CustomAdapter class which extends ArrayAdapter : CustomAdapter adapter = new CustomerAdapter(getApplicationContext(),R.layout.listview_item_row, weather_data); The constructor of CustomAdapter is as below: public CustomerAdapter(Context context, int layoutResourceId, weather[] data) { super(context, layoutResourceId, data); mlayoutResourceId = layoutResourceId; mcontext = context; mdata = data; } If I write this,

content must have a ListView whose id attribute is 'android.R.id.list'

喜欢而已 提交于 2019-12-23 01:54:37
问题 Your content must have a ListView whose id attribute is 'android.R.id.list' I'm getting this error which I have dealt with before. I have tried a bunch of different ids and so on but it's not helping. As you can see below the names do appear to be correct. I think it has something to do with the fact I am new to fragments and listfragments and so on. I have posted the relevant bits of code, if more is required I will provide it. Any ideas? public class DisplayInfo extends FragmentActivity {

getView showing random items when scrolling

流过昼夜 提交于 2019-12-23 01:41:45
问题 I have my class PlannerListAdapter that extends BaseAdapter and i have 2 problems in my getView() method. 1) When i set my adapter to the listview, everything it's ok, the listview show me all the elements i have in my List, I scroll down and i can see all the elements of the list. But when i scroll up, the elements starts to switch each other and also are being repeated, also, it is changing me the order of the elements, why is this happening? 2) In my BrandPlannersList i have a String[]

Android listView unwanted space between header view

∥☆過路亽.° 提交于 2019-12-23 00:30:06
问题 I'm adding 2 different views in my ListView header view but for some reason it create a 20dp space between those 2 views. How should I remove it? Thanks! Edit : The 2 views I add don't have any top/bottom padding or margins, I'm asking if there is any special "feature" in the ListView headerView about space/separator between views. Edit 2: it seems that the space between the view in my header view is tied to the dividerHeight parameter. Why? I mean it should only be applied as rows separator.

How to cancel the creation of a context menu after onCreateContextMenu() has been called

人走茶凉 提交于 2019-12-22 20:48:14
问题 I have an activity that registers a list view for the creation of the context menu: registerForContextMenu(getListView()); The problem is that a long click on some items should not present the context menu, because the items are disabled. public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); bool bDisplayMenu = isItemEnabled(((AdapterView.AdapterContextMenuInfo) menuInfo).position); if(bDisplayMenu) {

How to cancel the creation of a context menu after onCreateContextMenu() has been called

眉间皱痕 提交于 2019-12-22 20:46:04
问题 I have an activity that registers a list view for the creation of the context menu: registerForContextMenu(getListView()); The problem is that a long click on some items should not present the context menu, because the items are disabled. public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); bool bDisplayMenu = isItemEnabled(((AdapterView.AdapterContextMenuInfo) menuInfo).position); if(bDisplayMenu) {

Use custom selector for parent item and children items in ExpandableListView

懵懂的女人 提交于 2019-12-22 18:44:07
问题 I have expandable list which looks like this: Orange items are children and are shown when you press specific parent. Blue items are parents.I used this custom adapter to create this: (I picked this source code somewhere here on forum) public class ExpandableListAdapter extends BaseExpandableListAdapter { private Context context; private List<String> listDataHeader; private HashMap<String, List<String>> listDataChild; public ExpandableListAdapter(Context context, List<String> listDataHeader,

How to delete a custom listview item in android?

天大地大妈咪最大 提交于 2019-12-22 17:39:19
问题 I have a listview and a button in my layout file. I'am adding items to listview on click of that button. The listview should be empty when the activity is started but it should grow by adding the items to it. This is my code inside onCreate() : list = (ListView)findViewById(R.id.inverterListView); adapter = new ArrayAdapter<String>(InverterList.this, R.layout.inverters_list_row, R.id.inverterNumberTextViewInPanelListRow); list.setAdapter(adapter); And here iam adding the items to listview