我希望ListView用JSON的形式填充我的数据.该列表在理论上应该是无限的,如果滚动到底部,应用程序会请求更多数据.
Cursor或一个Array(List)适配器来链接我的在线数据库ListView吗?android json listview android-arrayadapter android-cursoradapter
我有一些数据光标.我有TextView,其可见性取决于游标项的某些属性.我使用SimpleCursorAdapter并覆盖getView方法.但实际上我并没有使用SimpleCursorAdapter的属性.是否更好地将我的适配器更改为CursorAdapter并覆盖newView和bindView方法?
这是场景:我有一个简单的ListView显示Twitter提要.我有一个CursorAdapter,它从sqlite中获取推文.当我在光标上调用requery()时,我希望将获取新的推文,这些推文已经被添加到数据库中.这一切都很好,在这种情况发生后,新的项目甚至可以在ListView中看到.
问题是滚动位置似乎是根据项目位置偏移量保存的.因此,假设我的ListView中的第一个可见位置是4.当我重新查询并且将2个新项目添加到列表顶部时,ListView将第一个可见项目滚动位置保持为4,但是因为列表中有两个新项目,我现在在第4位看到与我刷新之前不同的项目.此图像说明了之前和之后:

请注意Before,Tweet D是第一个可见项目,之后,Tweet B现在成为第一个可见项目.
我的问题是,在调用requery时如何根据光标位置保持相同的滚动位置,这样在这个例子中,Tweet D仍然是重新查询后的第一个可见项?
android xamarin.android android-listview android-cursoradapter
我目前用的是CursorAdaptera Loader.加载的数据Loader包含一个位置.我想从最近到最远的地方订购我的物品.我已经计算了显示它的距离,我现在需要找到一种动态排序数据的方法.
我可能CursorLoader每次修改数据时都会修改排序,但是一次又一次地执行相同的SQL查询只是为了改变顺序看起来对我来说太过分了......
有没有办法动态排序数据CursorAdapter?
sorting android android-location android-listview android-cursoradapter
我创建了一个ListView使用CursorAdapter.现在我正在尝试更新ListView和刷新ListView的值.
但我无法弄明白.如何使用Loader或changeCursor()刷新我的ListView
以下是我的设置代码CursorAdapter:
// SucessFully在这里完成
SQLDataSore datastore = new SQLDataSore(PrintContent.this);
Cursor cursor = datastore.getJSONData();
final CursorDemo cursorDemo = new CursorDemo(PrintContent.this, cursor);
list_View.setAdapter(cursorDemo);
Run Code Online (Sandbox Code Playgroud)
我Button onClick正在将值更新到数据库// SucessFully完成
btn_check.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View view ) {
String editTextValue = edit_check.getText().toString();
if (editTextValue!=null) {
SQLDataSore sqlDataSore = new SQLDataSore(PrintContent.this);
Cursor cursor_update = sqlDataSore.updateData(editTextValue);
//Here How Should I update my ListView ...?
}
}
Run Code Online (Sandbox Code Playgroud)
我的UpdateData方法:
public Cursor …Run Code Online (Sandbox Code Playgroud) android listview android-listview simplecursoradapter android-cursoradapter
我的应用程序的设置方式是我有一个由CursorLoader维护的ListView,由用户发布的帖子.每个帖子都有与之关联的用户评论.每个listitem底部都有一个自定义文本视图,可以滚动注释(使用向右或向左滑动).在每个自定义文本视图中,是与其特定帖子关联的注释列表.它类似于Google+应用中的评论,但项目是可滚动的.注释存储在与帖子不同的数据库表中.
我遇到的问题是,每次调用BindView时,我都在查询数据库并检索带有相关注释的游标并将其添加到自定义textview列表中.查询每个项目的注释数据库表似乎效率很低.所以我想知道是否有理想的方法来处理这个问题.我的代码看起来像:
public void bindView(View view, Context context, Cursor cursor)
final String rowid = cursor.getString(cursor.getColumnIndexOrThrow(Database.ROWID));
Cursor commentcursor = c.getContentResolver().query(DatabaseProvider.CONTENT_URI_COMMENTTABLE, freeWriteCommentColumns, Database.PARENTPOSTROWID + " =?", new String[]{rowid}, null);
commentcursor.moveToFirst();
while (commentcursor.isAfterLast() == false){
//get comment
//add to comment text view list
}
Run Code Online (Sandbox Code Playgroud)
我已经研究过CursorJoiners,但这似乎并没有用.我玩过JOINS,但这会使行数大于它需要的数量.我正在玩一个注册表游标的持有者,该游标是在创建适配器时创建的并设置为全局变量.这似乎是一个不错的途径,因为我不必每次都重新查询.我只是不确定如何处理这种情况.
sqlite android android-listview android-cursorloader android-cursoradapter
默认情况ListView下显示在我的SearchView包含文本下面的建议被截断.我希望文本完整显示(如有必要,可以在多行显示).
我已经提出了两种可能的方法来解决这个问题但是,由于没有在网上找到的例子,我希望有人在这里可以帮助...
方法#1/Q1:如何直接访问和修改包含SUGGEST_COLUMN_TEXT_1和SUGGEST_COLUMN_TEXT_1文本的TextView的外观?
方法#2/Q2:或者,SearchView有一个setSuggestionsAdapter(CursorAdapter adapter)看起来比方法#1更合适的方法(更多?).虽然我已经阅读了CursorAdapters并且已经在我的应用程序中实现了一个,但我不确定如何为SearchView配置一个(特别是在访问光标方面),所以任何人都可以帮我一些一般的指导还是一个骨架的例子?
以下是我的SearchViewFragment类中的现有代码:
public class SearchViewFragment extends Fragment {
public SearchViewFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View fragmentView = inflater.inflate(R.layout.fragment_search_view, container, false);
// Use the Search Manager to find the SearchableInfo related to this Activity
SearchManager searchManager = (SearchManager)getActivity().getSystemService(Context.SEARCH_SERVICE);
SearchableInfo searchableInfo = searchManager.getSearchableInfo(getActivity().getComponentName()); …Run Code Online (Sandbox Code Playgroud) customization android search-suggestion searchview android-cursoradapter
这是我的ListActivity ,单击列表后,它将启动一个新列表activity,其中显示每个景点的完整详细信息。我不知道如何实现完整的详细信息页面。你们能给我展示一些从以前的数据中检索数据的完整详细活动的代码吗list?
公共类 AttractionsListActivity 扩展 ListActivity {
私有静态MyDB mDbHelper;
String[] from = new String[] { Constants.TITLE_NAME , Constants.ADDRESS_NAME };
int[] to = new int[] {R.id.place_title, R.id.place_address};
私有游标c;
@覆盖
公共无效onCreate(捆绑保存实例状态){
super.onCreate(savedInstanceState);
mDbHelper = new MyDB(this);
mDbHelper.open();
c = mDbHelper.getplaces();
setListAdapter(新的SimpleCursorAdapter(这个,
R.layout.list_place,c,
从到));
最终ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
公共无效onItemClick(AdapterView父级,视图视图,int位置,长id){
Intent newActivity = new Intent(view.getContext(), Place.class);
启动活动(新活动);
}
});
}
}
我不知道如何实现此活动来处理 AttractionslistActivity.Class 中的操作
公共类地点扩展活动{
私有静态最终字符串CLASSTAG = Place.class.getSimpleName();
私有 TextView 标题;
私有 TextView 详细信息;
私有 TextView … android view settext simplecursoradapter android-cursoradapter
我正在尝试构建一个ListView,它代表一个食谱列表.我得到了使用a SimpleCursorAdapter来实现这一目标的概念.
但是,除了显示每个项目的配方图像和标题之外,我还想显示与配方相关的逗号分隔的成分串.鉴于游标仅适用于一个表(或视图),我不太清楚如何处理这个问题.
相关表格/栏目如下:
recipes (
_id integer primary key,
name text not null
)
ingredients (
_id integer primary key,
name text not null
)
recipes_ingredients (
_id integer primary key,
recipe_id integer not null,
ingredient_id integer not null
)
Run Code Online (Sandbox Code Playgroud)
编辑:关于这个问题的前两条评论让我相信没有足够的信息可以解释为什么我认为简单的JOIN是不够的.鉴于表结构,配方可以有多种成分,而不仅仅是一种.这意味着如果我尝试为单个食谱执行连接,我将最终得到如下内容:
SELECT r.name AS recipe, i.name AS ingredient
FROM recipes r
INNER JOIN recipes_ingredients ri ON ri.recipe_id=r._id
INNER JOIN ingredients i ON ri.ingredient_id=i._id;
recipe | ingredient
------------------+---------------------
Chocolate Milk | milk
Chocolate Milk | chocolate …Run Code Online (Sandbox Code Playgroud) 我有cursoradapter的listview.现在我想在listview中实现原生快递广告.
我已经看到使用简单的baseAdapter实现原生广告,通常我们List<Object>用于将数据传递给适配器并检查getView()方法内的项目类型以添加广告.
@Override
public View getView(int position, View convertView, ViewGroup parent)
throws IllegalArgumentException {
Object item = getItem(position);
if (item instanceof Listing) {
// Listing items already have all the data required, so they just need to be displayed.
return listingLayout;
} else if (item instanceof AdPlacement) {
return ((AdPlacement) item).getView(convertView, parent);
} else {
// Any unknown items will cause exceptions, though this shouldn't ever happen.
throw new IllegalArgumentException(
String.format("Adapter can't handle getView() for list …Run Code Online (Sandbox Code Playgroud) android listview android-cursoradapter native-ads google-admob
android ×10
listview ×3
cursor ×2
adapter ×1
google-admob ×1
join ×1
json ×1
native-ads ×1
searchview ×1
settext ×1
sorting ×1
sqlite ×1
view ×1