有人可以用简单的话来解释我的用法getViewTypeCount()和getItemViewType()方法ArrayAdapter吗?
我有一个ListView和一个BaseAdapter.我正在从webservice下载产品并在listview上显示.它在listview上正确显示.
但是当我滚动ListView时,显示随机位置的行意味着有时第三行显示在第一个位置,中间位置行显示在最后位置,依此类推.
这是我的适配器类
public class ProductListAdapter extends BaseAdapter implements OnClickListener{
LayoutInflater inflater;
ArrayList<Product> arrProducts;
Context c;
public ProductListAdapter(Context c, ArrayList<Product> arrProducts) {
super();
inflater = LayoutInflater.from(c);
this.arrProducts = arrProducts;
this.c = c;
}
@Override
public int getCount() {
return arrProducts.size();
}
@Override
public Object getItem(int position) {
return arrProducts.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View v, ViewGroup parent) {
Product product = null;
if(v == null) {
v = inflater.inflate(R.layout.product_listview_row, …Run Code Online (Sandbox Code Playgroud) 
在附加图像中,SelectAll checkbox存在于活动中,并且都checkboxes在适配器内.如果我checked SelectAll然后在适配器中检查所有复选框,如果我取消选中,则取消选中所有复选框.它发生得很好.
但我想,如果我checked SelectAll和之后,如果我uncheked在适配器中的一个或多个复选框然后SelectAll checkbox should unchecked.如果没有检查SelectAll如果我手动检查适配器中的所有复选框然后SelectAll checkbox should checked自动.
我怎样才能做到这一点.
吼叫是我的代码., http://pastebin.com/5pUJJC42
我有更多数据的列表视图[文本视图和复选框控件].我将从列表视图中选择项目,并在下一个活动中显示所选项目.我的问题是,例如,如果我在列表视图中选择第20和第25项,它将在下一个活动中显示其他一些项目.即列表视图位置在滚动时会发生变化.
我通过单击项目上的复选框选择项目.在checkbox.setOnChanged监听器中,我编写了代码选择与否的代码.如果我选择第25个项目并滚动列表视图,则调用getview方法,并且checkbox.setonChanged方法将更改所选位置. 我最后打印了logcat.
我的编码格式:
public class ListContact extends ListActivity {
public void onCreate(Bundle icicle){
.....
ArrayAdapter<Model> adapter = new MyCustomArrayAdapter(this,getModel());
setListAdapter(adapter);
}
....
private List<Model> getModel() {
List<Model> list = new ArrayList<Model>();
Iterator<String> itr = constant.selectname.iterator();
while (itr.hasNext()) {
list.add(get(itr.next().toString()));
}
return list;
}
private Model get(String s) {
return new Model(s);
}
}
Run Code Online (Sandbox Code Playgroud)
MyCustomArrayAdapter.java:
public class MyCustomArrayAdapter extends ArrayAdapter<Model> {
private final List<Model> list;
private final Activity context;
constant con ;
public MyCustomArrayAdapter(Activity context, List<Model> list) {
super(context, …Run Code Online (Sandbox Code Playgroud) 我已经设置了一个ListView,每行包含一个Checkbox(以及TextView).出于某种原因,当我"检查"其中一个方框时,它似乎"检查"ListView中相反的方框(即选择顶部框时,底部复选框将被选中而顶部仍未选中).
我知道这里没有任何代码可以使用,但我只是想知道这是否是一般问题?如果没有,我可以尝试发布一些代码.谢谢!

在上面的图像中,有一个列表视图,其中包含用户可以下载的项目列表.
这是告诉用户他可以下载文件的图像.下载完成后,图像将变为
.我的问题是当我下载文件时,状态图像(表示下载已完成)被更改为另一行,相反,它应该更改为我选择的行.目前,如果我在列表中下载第一个文件,则图像会在列表中的第4个或第5个项目中更改.此外,当我尝试从列表中下载任何其他文件时.它打开了最后下载的文件(这是应用程序的功能,如果文件已经下载,然后在pdf阅读器中打开),即,如果我在列表中下载第一个文件,然后去第二个项目,然后而不是下载第二个文件,它打开上次下载的文件.此外,如果我滚动列表视图,下载的状态也会更改为列表中的其他项目.下面是我的适配器代码:
public class DownloadListAdapter extends BaseAdapter {
Context ctx;
public ArrayList<DownloadListDao> mDownloadList;
String readMoreLink;
public static final String TAG = "DownloadListAdapter";
ProgressDialog mProgressDialog;
private boolean isSDCardPresent;
File tieDir;
int downloadState[];
public DownloadListAdapter(Context ctx,
ArrayList<DownloadListDao> mDownloadList) {
this.ctx = ctx;
this.mDownloadList = mDownloadList;
downloadState = new int [mDownloadList.size()];
for(int i = 0; i < mDownloadList.size(); i++) {
downloadState[i] = 0;
}
tieDir = new File(Environment.getExternalStorageDirectory().toString()
+ "/tie");
}// Constructor
public int getCount() {
return this.mDownloadList.size();
}// getCount
public Object …Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,我需要从联系人簿中获取所有联系人并显示.我希望用户选择一些联系人并将其添加到保存在db中的组中.
我创建了一个自定义列表视图 - contactitem.xml-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/contactname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:ellipsize="end"
android:singleLine="true"
android:clickable="true"/>
<TextView
android:id="@+id/contactnum"
android:layout_width="wrap_content"
android:textColor="@color/White"
android:clickable="true"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="@string/add_contacts"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我有一个SelectContact类,用于从联系簿中获取联系人 -
public class SelectContacts extends Activity implementsOnItemClickListener {
private List<Contact> list = new ArrayList<Contact>();
private ListView contact_list;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.selectcontacts);
contact_list=(ListView)findViewById(R.id.contactsListView);
ContentResolver cr = getContentResolver();
Cursor cur = …Run Code Online (Sandbox Code Playgroud) 我想我已经尝试了所有东西(使焦点成为可能:假!!)并且无论如何我无法捕捉列表项目中的所选复选框.即使是OnItemClickListener,也不会响应任何点击.
如何在列表项中检索选中的复选框?我的列表项包括:图像视图,4个文本视图和复选框
一些代码:
这是在我的ListActivity类中:
final String columns[] = new String[] { MyUsers.User._ID,
MyUsers.User.MSG, MyUsers.User.LOCATION };
int[] to = new int[] { R.id.toptext, R.id.bottomtext,R.id.ChkBox, R.id.Location};
Uri myUri = Uri.parse("content://com.idan.datastorageprovider/users");
Cursor cursor = getContentResolver().query(myUri, columns, null, null, null);
startManagingCursor(cursor);
ListCursorAdapter myCursorAdapter=new ListCursorAdapter(this,
R.layout.listitem, cursor, columns, to);
this.setListAdapter(myCursorAdapter);
Run Code Online (Sandbox Code Playgroud)
这是我的Custom Cursor适配器类:
public class ListCursorAdapter extends SimpleCursorAdapter
{
private Context context;
private int layout;
public ListCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to)
{
super(context, layout, c, from, to);
this.context = context;
this.layout …Run Code Online (Sandbox Code Playgroud) 我正在开发Listview,其中可以进行多项选择,现在问题是当我向下或向上滚动选项丢失并在除了所选项目之外的任何其他项目上进行选择.
以下是我的活动.
public class ContactPickerActivity extends Activity {
private ArrayList<Contact> arr = new ArrayList<Contact>();
private Context context;
private ListView list;
private ContactArrayAdapter adapter;
private String strName,strNumber;
private View view;
public static ArrayList<Boolean> arrBoolean = new ArrayList<Boolean>();
@Override
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
setContentView(R.layout.contact_picker);
ProgressDialog pd = new ProgressDialog(this);
list = (ListView)findViewById(R.id.contactList);
arr = new ArrayList<Contact>();
context = ContactPickerActivity.this;
arr = displayContacts();
Log.i("ContactPicker", "Completed Displaying Contact list ::: " + arr.size());
adapter = new ContactArrayAdapter(this,arr);
list.setAdapter(adapter);
// list.setAdapter(new ArrayAdapter<String>(this,
// …Run Code Online (Sandbox Code Playgroud)