adapter

List items with alternating colors

一个人想着一个人 提交于 2019-11-27 18:37:47
问题 I have a list view and an adapter that sets alternating background colors to the list items ("zebra" list style): public View getView(final int position, View convertView, ViewGroup parent) { int colorPos = position % colors.length; ... convertView.setBackgroundColor(colors[colorPos]); return convertView; } But now, when i select an item using scroll wheel, or when I click an item, the original colors for selecting/clicking do not override my custom backgrounds (I can see the original color

第十次作业

℡╲_俬逩灬. 提交于 2019-11-27 18:05:21
package com.example.shopping; import java.util.ArrayList; import com.example.adapter.shopAdapter; import com.example.bean.shopBean; import Database.SQLiteHelpe; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.Toast; public class MainActivity extends Activity implements View.OnClickListener { private static final Context Context = null; private EditText mName; private EditText mPrice; private EditText mAmount;

Implementing Circular Scrolling In PagerAdapter

走远了吗. 提交于 2019-11-27 17:45:25
I am using PagerAdapter for horizontal swiping for showing newspaper pages in my app. Currently I want to implement the circular scrolling in this app.Right now what I have done is whenever I am getting on last page I try to set the currentItem to first page i.e that functionality working for last page to first page,but the problem is that how can I go to last page from first page. Here I am pasting my code related to pagerAdapter & onPageChangeListener:- awesomeAdapter = new AwesomePagerAdapter(awesomePager); awesomePager.setAdapter(awesomeAdapter); awesomePager.setPageMargin(10);

How to remove listview all items

送分小仙女□ 提交于 2019-11-27 15:31:39
问题 In my app, if you click on a button then i want to remove all the listview items. Here, i am using the base adapter for adding the items to the list view. How can i remove the listview items dynamically. 回答1: Call setListAdapter() again. This time with an empty ArrayList. 回答2: ListView operates based on the underlying data in the Adapter . In order to clear the ListView you need to do two things: Clear the data that you set from adapter. Refresh the view by calling notifyDataSetChanged For

Cannot add header view to list — setAdapter has already been called

自作多情 提交于 2019-11-27 14:37:52
I have one edittext field and one "search" button. When I click on search, I have to display a list view with data corresponding to the values entered in the edittext. I have added a header to my list using addHeader(). When I do search first time, I am able to display data in List successfully. But when I do search again, I am getting the below error. FATAL EXCEPTION: main java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called. at android.widget.ListView.addHeaderView(ListView.java:261) at android.widget.ListView.addHeaderView(ListView.java:284)

Android : BaseAdapter how to?

房东的猫 提交于 2019-11-27 14:15:02
Ok, I have been searching thick and thin, and I am having some issues implementing a BaseAdapter. I have been able to implement a Simple Cursor Adapter http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List7.html as per the example above. There is a pretty good BaseAdapter example here : List14 google example I am wanting to create my own List Adapter using BaseAdapter to show a listView, with multiple items from a Database. I know this can be done using the Simple Cursor Adapter, but I am looking to handle rows differently, so I want to be able to draw

When getView() in ArrayAdapter is called

大兔子大兔子 提交于 2019-11-27 13:48:42
问题 When creating a customized adapter for ListView in android, I see that I have to create a class the extends ArrayAdapter class and implements the getView(..) method. All of that is OK, but I want to know the sequence of calling methods and executing. i.e. in which point of code the getView() is being called ? 回答1: From android docs - An Adapter object acts as a bridge between an AdapterView (such as ListView in your case) and the underlying data for that view. The Adapter provides access to

Android ArrayAdapter.Add method not working

南笙酒味 提交于 2019-11-27 13:45:24
问题 The ArrayAdapter.add() method is not working for me. I am using Eclipse Helios 3.6 with ADT Plugin, Target Source is a Froyo 2.2 emulator and 2.2 HTC Evo 4g. Here is my java class import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; public class Main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String[] entries = {"List Item A", "List Item B"};

Android: EfficientAdapter with two different Views

半腔热情 提交于 2019-11-27 12:41:26
问题 I'm using an extended version of BaseAdapter based on the EfficientAdapter example from the SDK demo samples. My data is basically an object ( ListPlaces ) which holds an ArrayList with the actual list of places, accessible via listPlaces.getValues() . This ArrayList data is sorted by range and the ArrayList consist of some special items (separators), with no data, but a separator flag set to true . Now whenever my EfficientAdapter gets a data object which is a separator it returns false for

How to implement an endless gallery in Android?

扶醉桌前 提交于 2019-11-27 12:14:45
I am using a gallery layout in my application. It is working when the user moves the pictures in the gallery from left to right (it is infinite that means elements are repeated again). But when the user moves from right to left and reaches the first element, it doesn't. After then no elements are coming. But I want to repeat elements from this side also. Can you give me some suggestions? Gallery g = (Gallery) findViewById(R.id.gallery); g.setAdapter(new ImageAdapter(this)); g.setFocusable(true); g.setSelection((int)(Integer.MAX_VALUE / 2) - (Integer.MAX_VALUE / 2)% mImageIds.length); g