android-listview

OnScrollListener.onScroll() called on item click in a ListView

喜夏-厌秋 提交于 2019-12-21 16:59:22
问题 I have a ListView with an OnScrollListener and an OnItemClickListener . When I click on an item, both the onScroll() method in the OnScrollListener and the OnItemClickListener are fired. Is there a way to prevent this behaviour? If not, how can I tell, inside onScroll() , if the user is really scrolling or he's just clicking? 回答1: I think onScrollStateChanged should also be called with scrolling. Then you should be able to see if the state is idled or scrolling through the constants defined

how to use onClickListener method of Button on a ListView

那年仲夏 提交于 2019-12-21 16:49:08
问题 I have a custom ListView which contains a Button . The function of this button is Delete button. Whenever user click to this button, the current Row will be deleted. How can I do it? How can I set onClickListener for this button? How can I catch the row Id which this button is on? Thanks in advance. 回答1: In your Custom Adapater class's getView() buttonDelete.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Use position parameter of your getView() in this

android ListView : scrollTo doesn't work

浪子不回头ぞ 提交于 2019-12-21 13:11:34
问题 I have a view that contains a ListView which is binded to a cursor adapter. When The cursor content change I want to keep the ListView at the top then in my custom cursor adapter I added : @Override protected void onContentChanged() { // ... myListView.scrollTo(0, 0); } but this doesn't work. Then I read somewhere to queue this action like this : myListView.post(new Runnable() { public void run() { myListView.scrollTo(0, 0); } }); but this doesn't work either. How can I keep the ListView at

Populate ListView on Fragment after Async done from Activity

霸气de小男生 提交于 2019-12-21 12:35:58
问题 I have main activity which will get JSON data from a url async This is MainActivity.java public class MainActivity extends FragmentActivity implements ActionBar.TabListener{ private ViewPager viewPager; private TabsPagerAdapter mAdapter; private ActionBar actionBar; //Tab titles private String[] tabs = {"Sermons", "More"}; private String[] sermonsList = new String[0]; //JSON URL for sermonList data private static String sermonListJSONUrl = "https://dl.dropboxusercontent.com/u/12345/index.php"

Force onSizeChanged for ListView

那年仲夏 提交于 2019-12-21 12:18:36
问题 I have a listview which gets assigned with different datasets dynamically. This works fine. I have also made fastScrollEnabled to be true. For the sectionIndexer to be updated I need to call list.setFastScrollEnabled(false); list.setFastScrollEnabled(true); The problem is the index shows in top left and this is a know issue. As a work-around whenever I change the orientation the index is again correctly shown. To test this I have implemented a custom ListView and the observation is if I can

Why does ListView stays above TextView in ListPreference dialog?

让人想犯罪 __ 提交于 2019-12-21 12:09:13
问题 I need to create a custom ListPreference dialog so that I can add some header text (a TextView) above the List (ListView). I've created MyListPreference class that extends ListPreference and overrides onCreateDialogView(): @Override protected View onCreateDialogView() { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = (View) inflater.inflate(R.layout.dialog_preference_list, null); return v; } My XML layout dialog_preference

ListView does not update until keyboard is hidden

落爺英雄遲暮 提交于 2019-12-21 09:21:52
问题 I have a DialogFragment and in it's layout I have a EditText and a ListView . The Listview basically shows the list of contacts (Initially this list has 0 items). When the edittext 's value is updated I populate the list with contacts that have the text typed in the EditText . On the EditText I have used a addTextChangedListener to update the list with desired contacts as the user types in a name or email address of the contact. The weird problem I am facing is that the list (or maybe the

EditText inside ListView lost focus [duplicate]

扶醉桌前 提交于 2019-12-21 09:05:14
问题 This question already has answers here : Focusable EditText inside ListView (12 answers) Closed 6 years ago . I have recently face this problem and I want to share with you my solution. Problem : You have a ListView with a Edit Text for each row like this: MainList.xml <ListView android:id="@+id/listViewServ" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/> RowList.xml <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android

Hide row from ListView without taking up space

断了今生、忘了曾经 提交于 2019-12-21 07:57:16
问题 I have a ListView with an associated ArrayAdapter that displays its contents in several activities. Unfortunately it got necessary now, that my ListView in one of the settings does not display all its elements, but just the ones where "property" is not set to true. I would like to avoid to use two ArrayAdapters with different content, since then I somehow need to keep them in sync. I tried it like this (this method now just assumes that getView is called in the setting where we want to hide

Header View height in a ListView

冷暖自知 提交于 2019-12-21 07:20:10
问题 I'm working with a ListView that is part of an ListFragment. I want to add a header with a specific/custom height but it does not matter what I put in the height of the header view, always it has the same height. Is possible to modify the header view height of a ListView? Below the code I use: header.xml <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="100dp" /> ListFragment @Override public void onActivityCreated