android-listview

Android setOnItemClickListener

為{幸葍}努か 提交于 2019-12-12 18:26:15
问题 I'm not able to initiate the " OnItemClickListener ". You can see my code snippet ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main, new String[] { "title"}, new int[] { R.id.item_title}); setListAdapter(adapter); final ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { @SuppressWarnings("unchecked") HashMap<String, String> o =

Changing cursor in CursorAdapter is not properly updating list item views

梦想与她 提交于 2019-12-12 18:11:56
问题 This question is very similar to many other questions on StackOverflow, but I think it merits its own post due to a difference in approach compared to other questions here. I have a custom adapter that extends CursorAdapter . I'm updating the data and calling notifyChange on the appropriate URI in order to refresh the cursor. In debugging, I can see that this is working properly. Unfortunately, my list views are not being recreated. The reason that I need them to be recreated is because of my

How Can I Prevent Activation For Some ListView Items When The Selection Mode Is MultiChoiceModal?

試著忘記壹切 提交于 2019-12-12 17:12:16
问题 I have a customized GridView populated by a customized BaseAdapter. The selection mode of the GridView is MultiChoiceModal. I want to control which items can be activated when long clicked while still ensuring they respond to (short) click events. BaseAdapter has a method called isEnabled , the perfect solution would be if it had a method isActivatable that behaved analogously. The next best solution would be to intercept long clicks and pass them along to the default handler only when

How to detect which button and at which position clicked in CustomList

岁酱吖の 提交于 2019-12-12 16:29:50
问题 I am using a custom listview in which i have two button for every item. following is the my item xml. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="10"> <Button android:id="@+id/btn_sound" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_gravity="left" android:layout_marginLeft="3dp" android:layout_marginTop="3dp"

android : listview: get cursor value on item click

扶醉桌前 提交于 2019-12-12 15:53:45
问题 I create a database and table (categories) with columns (_id, title, ...) I want to read categories from db and show category list as a listview. here is y code: public class MainActivity extends listActivity{ private ArrayAdapter arrayAdapter; ArrayList results = new ArrayList(); ListView catlist; Cursor cur; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); catlist = getListView(); int parentid = getIntent

Android - ArrayAdapter duplicates ListView items

馋奶兔 提交于 2019-12-12 15:17:01
问题 I have a ListView widget (positioned below other UI elements) that is part of an Activity that does not extend ListActivity . I am trying to write a basic feature that adds extra items to the ListView upon clicking a Button . This data is obtained from an EditText . I define the Adapter , an ArrayAdapter in my case, for the ListView in onCreate() and set the adapter for the ListView using setListAdapter() . However when I try to add an extra item to the ListView two items are added in the

Determine ListView height before loading the list

会有一股神秘感。 提交于 2019-12-12 15:02:17
问题 Is it possible to determine the height of a ListView before it is rendered on the screen? If my ListView were to have, say 3 items, and the height is confined to these 3 items (and the ListView doesn't take up the entire screen's height), can I determine the height before Android displays the items on the screen? 回答1: Use the following method to get and set the height based upon children present private static void setListViewHeightBasedOnChildren(ListView iListView) { ListAdapter listAdapter

creating Json from sqlite in Android

空扰寡人 提交于 2019-12-12 14:47:20
问题 i want to have json file from my sqlite and save it in asset.myJson.json. following is my codes,i want to see result in myJson.json. please help me how to import data to myJson.json. private JSONArray jsongetResult(){ SQLiteDatabase database = openOrCreateDatabase("ORCL", MODE_PRIVATE, null); Cursor cursor = database.rawQuery("SELECT id,title,qty,price FROM CART;", null); JSONArray resultSet = new JSONArray(); cursor.moveToFirst(); while (cursor.isAfterLast() == false) { int totalColumn =

Fetch data from JSON Category wise

杀马特。学长 韩版系。学妹 提交于 2019-12-12 14:42:35
问题 I am writing an app in which i am fetching data from JSON , and i am able to fetch list of Categories but whenever i do click on any of the Category not getting List of Products under that particular Category always getting Blank activity . JSON: [ { "categoryId": "1", "categoryTitle": "SmartPhones", "SmartPhones": [ { "itemId": "1", "itemTitle": "Galaxy Mega 5.8" }, { "itemId": "2", "itemTitle": "Galaxy Mega 6.3" } ] }, { "categoryId": "2", "categoryTitle": "Tablets", "Tablets": [ { "itemId"

Selected list item color moves on scrolling the listView in Android

烂漫一生 提交于 2019-12-12 13:33:59
问题 In my Android application I am using listview. The code for list view is as follows <ListView android:id="@+id/inputselect_listview" android:layout_width="match_parent" android:layout_height="wrap_content" android:choiceMode="singleChoice" android:footerDividersEnabled="true" android:headerDividersEnabled="true" android:listSelector="@drawable/list_selector" android:splitMotionEvents="true" > </ListView> When user selected one item from the listview then background color of list item changes