标签: simplecursoradapter

SimpleCursorAdapter处理空光标

我正在使用自定义的SimpleCursorAdapter.如果在数据库/游标中找不到任何条目,则目前我的列表保持为空.现在,如果游标/数据库中没有条目,我想在列表中显示一条消息.我该如何处理这个事件?

android simplecursoradapter

1
推荐指数
1
解决办法
2566
查看次数

列'_id'不存在SimpleCursorAdapter重新访问

我想使用SimpleCursorAdapter来填充我的ListActivity,但是我得到了经典的异常,因为我的Cursor中没有'_id'字段.不幸的是,这种类型的查询没有为我提供一个字段,我可以将其用作我的_id字段的形式:

SELECT DISTINCT room from tblRates WHERE resid='ABC' AND date='2011-10-17'
Run Code Online (Sandbox Code Playgroud)

由于DISTINCT我不能只添加_id.那么如何设置自定义适配器呢?

顺便说一句,我已经看过这篇文章,所以我明白为什么我会收到这个错误.只是想知道如何使用我正在做的查询类型获取_id:

Android专栏'_id'不存在?

sqlite android listactivity simplecursoradapter

1
推荐指数
1
解决办法
3928
查看次数

使用SimpleCursorAdapter.ViewBinder更改Listview中的文本颜色

我已经列出了使用数据库的名称SimpleCursorAdapter,我想使用SimpleCursorAdapter.ViewBinder's方法更改特定名称的颜色.我在运行此方法时遇到问题,我的数据库包含不同的名称,但ListView会将所有namse显示为一个特定名称.我究竟做错了什么?如何更改特定名称的文本颜色?有可能用ViewBinder吗?

这是我的代码部分ViewBinder:

    SimpleCursorAdapter.ViewBinder binder = new SimpleCursorAdapter.ViewBinder() {

    @Override
    public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
        // TODO Auto-generated method stub
        String[] temp = dh.return_result();
        tv = (TextView)findViewById(R.id.textView1);
        tv = (TextView) view;
        for(int i = 0; i<temp.length; i++)
        {
            if(temp[i].equalsIgnoreCase("Ameer Zhann"))
            {
                tv.setText(temp[i]);
                tv.setTextColor(Color.rgb(58, 58, 224));
                return true;
            }
        }
        return false;
    }
};
Run Code Online (Sandbox Code Playgroud)

这是我的输出图像:

图片

我怎么解决这个问题?

android android-listview simplecursoradapter android-viewbinder

1
推荐指数
1
解决办法
2717
查看次数

自定义SimpleCursorAdapter,背景颜色为偶数行

我想实现一个自定义SimpleCursorAdapter,它只在偶数行上显示背景颜色(在我的情况下为蓝色).我的实现如下:

public class ColoredCursorAdapter extends SimpleCursorAdapter {
    String backgroundColor;

    public ColoredCursorAdapter(
            Context context,
            int layout,
            String backgroundColor,
            Cursor c,
            String[] from,
            int[] to,
            int flags) {
        super(
                context, 
                layout, 
                c, 
                from, 
                to, 
                flags);
        this.backgroundColor = backgroundColor;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        super.bindView(view, context, cursor);
        if(cursor.getPosition() % 2 == 0) {
            view.setBackgroundColor(
                    Color.parseColor(backgroundColor));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

它在开始时工作正常,但是当我反复向下滚动列表时,所有行都变为蓝色.

提前致谢.

android listview background list simplecursoradapter

1
推荐指数
1
解决办法
1991
查看次数

SimpleCursorAdapter不断为API 10抛出错误

我的项目的minSDK为10,目标为17.我已经android-support-v4.jar通过右键单击.jar文件并选择"Build Path - > Add to Build Path"添加到项目构建路径中.当我清理项目时,错误SimpleCursorAdapter就消失了.但是,当我尝试运行该活动时,我收到以下错误:

01-05 23:42:56.187:E/AndroidRuntime(483):java.lang.NoSuchMethodError:android.widget.SimpleCursorAdapter.

此外,如果我对活动进行更改,我每次都要清理项目,只是为了摆脱错误SimpleCursorAdapter.

我在这里错过了什么?为什么这不正常?

android simplecursoradapter android-support-library

1
推荐指数
1
解决办法
754
查看次数

NoSuchMethodError SimpleCursorAdapter for old version of android(2.3.3)

我正在开发集成Sherlock的小型android应用程序.在我的应用程序中,我正在使用Sherlock列表片段,其中我显示从本地数据库获取的列表项.

lv = getListView();
from = new String[] { Table.COLUMN_DESC1,COLUMN_DESC2, COLUMN_COUPONID };
to = new int[] { R.id.textView1, R.id.textView2, R.id.textView4 };
adapter = new SimpleCursorAdapter(this.getActivity(),R.layout.coupon, null, from, to, 0);
setListAdapter(adapter);
getLoaderManager().restartLoader(0, bundle, this);
Run Code Online (Sandbox Code Playgroud)

现在的问题是,当我在Android的ics版本上运行此代码时它的工作正常但是当我在Android 2.3.3上运行它时它会产生以下问题.

我的应用程序包含一个主要活动和两个片段f1,f2

当我从f1切换到f2时工作正常没有任何错误..

当我再次从f2切换到f1时工作正常

但是当我再次从f1切换到f2时,它会出现以下错误.

01-03 01:37:04.175: E/AndroidRuntime(8010): FATAL EXCEPTION: main
01-03 01:37:04.175: E/AndroidRuntime(8010): java.lang.NoSuchMethodError:android.widget.SimpleCursorAdapter.<init>
Run Code Online (Sandbox Code Playgroud)

在较新版本的Android上可以正常使用此代码,但在旧版本上它工作正常....我无法弄清楚它背后的问题是什么..需要帮助...谢谢...

android adapter simplecursoradapter actionbarsherlock

1
推荐指数
1
解决办法
1546
查看次数

如何使用SimpleCursorAdapter更改特定行的背景

我正在尝试根据我的SQLite DB中的信息创建一个列表视图.我目前设置的代码只是相应地显示每一行,并用数据填充3个textviews.我希望能够使用某种If语句来检查其中一个值是否为"Room1",然后将该行的背景设置为某种颜色.

这样,列表中的每一行将根据数据的"空间"具有不同的背景.

我试过扩展SimpleCursorAdapter,但是我对如何得到我想要的东西感到有点迷茫.

以下是我目前对SimpleCursorAdapter的看法:

Cursor notesCursor = myDbHelper.fetchDayPanelNotes(type, day);
startManagingCursor(notesCursor);
String[] from = new String[]{DataBaseHelper.KEY_NAME, DataBaseHelper.KEY_ROOM, DataBaseHelper.KEY_TIME};

int[] to = new int[]{R.id.text1, R.id.text2, R.id.text3};

SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.main_row, notesCursor, from, to);
setListAdapter(notes);
Run Code Online (Sandbox Code Playgroud)

android listview simplecursoradapter

0
推荐指数
1
解决办法
5069
查看次数

Listview自定义布局多项选择

我想创建一个允许多项选择的列表视图.典型的解决方案是获取游标并使用SimpleCursorAdapter.

        SimpleCursorAdapter adapter2 = new SimpleCursorAdapter(this,
                    R.layout.simple_list_item_multiple_choice, cur2, cols2, views2);
Run Code Online (Sandbox Code Playgroud)

使用时,我能够正常工作R.layout.simple_list_item_multiple_choice.当选择多个项目时,我会使复选标记生效.

所以我决定尝试使用自定义布局.这是我的布局的XML代码.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:textAppearance="?android:attr/textAppearanceLarge" />


    <TextView
        android:id="@+id/lookup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:textAppearance="?android:attr/textAppearanceSmall" />


    <TextView
        android:id="@+id/hasphone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:textAppearance="?android:attr/textAppearanceSmall" />

    <CheckedTextView
        android:id="@+id/checkedTextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:checkMark="?android:attr/listChoiceIndicatorMultiple"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

所以这是我的问题.使用相同的代码并在我的listview上将ChoiceMode设置为多个,可以很好地扩展布局.光标中的数据填充正确.

但是,我遇到的问题是,当我点击该项目时,复选标记不会显示为选中(框中的复选框).是否有一些我不想要的东西,不涉及创建自定义适配器?


l2.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
Run Code Online (Sandbox Code Playgroud)

l2是我的列表视图.

xml android listview simplecursoradapter

0
推荐指数
1
解决办法
6072
查看次数

获取具有特定ID的行的ListView中的位置

我有一个ListView,SimpleCursorAdapter我想知道如何获得ListView一个身份证的位置?我需要它来执行单击列表中的特定行,如下所示

lv.performItemClick(lv, pos, lv.getItemIdAtPosition(pos));
Run Code Online (Sandbox Code Playgroud)

android click android-listview simplecursoradapter

0
推荐指数
1
解决办法
1159
查看次数

ListView中setAdapter中的NullPointer异常

当wifi打开时 - 所有工作,但当它关闭 - 我得到nullPointer异常

package ua.khuta.myskidka;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.database.Cursor;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class FragmentNews extends Fragment {
private View v;
ListView lvNews;
Database db;
mySCadapter scAdapter;
public String DEBUG_TAG = "myLogs";
String[] from = new String[] { Database.NEWS_TITLE, Database.NEWS_IMAGE_URL,
        Database.NEWS_SHORT_DESCRIPTION };
int [] to = new int[] { R.id.item_news_tv_title, R.id.item_news_iv_image,
        R.id.item_news_tv_short_description };



@Override
public …
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception simplecursoradapter

0
推荐指数
1
解决办法
2570
查看次数