标签: android-adapterview

android如何在适配器内调用startActivityForResult

我有一个适配器类:

public class AdapterAllAddress extends BaseExpandableListAdapter {
private Context context;
    public AdapterAllAddress(Context context,
            ArrayList<AllAddressesGroup> groups) {
        // TODO Auto-generated constructor stub
        this.context = context;
    }
}
Run Code Online (Sandbox Code Playgroud)

我想在startActivityForResult点击按钮时打电话,我知道我可以这样打电话startActivity:

context.startActivity() 
Run Code Online (Sandbox Code Playgroud)

但我正在寻找有结果的活动,请问怎么样?

java android android-adapter android-activity android-adapterview

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

Gallery/AdapterView子绘图状态

我正在使用一个图库视图,其中对应于每个项目的视图是非平凡的,包括文本和多个按钮.

当我单击拖动图库视图(某个位置不在其中一个按钮上)时,按钮的可绘制状态变为按下并显示为当前正在按下所有按钮.此外,对于所选状态会发生相同的行为(例如,子TextView的所有文本都会更改颜色).

我试图阻止这种行为,并找到了android:duplicateParentState xml属性以及setDuplicateParentStateEnabled属性.这似乎应该完成我想做的事情,但似乎没有任何效果.

有任何想法吗?

viewstate android gallery drawable android-adapterview

7
推荐指数
2
解决办法
2282
查看次数

使用AdapterView和addView时出现问题

我希望下面的类显示一些textview/buttons/spinners,以及包含已解析数据的ListView.但是listview/adapter/addview会造成一些麻烦.这是我得到的错误:

java.lang.UnsupportedOperationException:AdapterView不支持addView(View,LayoutParams)

我感觉它与我的xml文件有关,但我不太确定.这是我的代码:

public class StatisticsScreen extends ListActivity{

private List<Message> messages; 

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.statisticsscreen);

    loadFeed();

    //other textviews and listeners added
}

private void loadFeed() {

    try{
        BaseFeedParser parser = new BaseFeedParser();
        messages = parser.parse();
        List<String> titles = new ArrayList<String>(messages.size());
        for (Message msg : messages){
            titles.add(msg.getTitle());
        }
        ArrayAdapter<String> adapter = 
        new ArrayAdapter<String>(this, R.layout.xmldatarow,titles);

        this.setListAdapter(adapter);           
    } catch (Throwable t){
        Log.e("AndroidNews",t.getMessage(),t);
    }       
}
Run Code Online (Sandbox Code Playgroud)

我的statisticsscreen xml:

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">

<LinearLayout android:id="@+id/statsviewlayout"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@color/black">
    //other layouts/textviews/buttons added …
Run Code Online (Sandbox Code Playgroud)

parsing android listview adapter android-adapterview

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

GridView.setOnItemClickListener不起作用

我从2days开始遇到一个问题.我有一个网格视图,我需要显示图像.当我点击网格项时,它必须转到下一个活动.我能够在gridview中显示图像但事情是什么时候我点击它没有响应的项目​​..(OnItemClickListener不工作).我无法在我做错的地方追踪我的问题.

         package com.logictreeit.mobilezop.fragments;

     import android.app.Activity;
     import android.content.Context;
     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.AdapterView;
     import android.widget.AdapterView.OnItemClickListener;
     import android.widget.GridView;

     import com.logictreeit.mobilezop.adapters.PhotoAdapter;
     import com.logictreeit.mobilezop.custom.Utils;

      public class Dup_AlbumPhotosFragment extends Fragment implements
                OnItemClickListener {

private static final String TAG = "AlbumPhotos Fragment";
private GridView gridView;
private Context mContext;
private PhotoAdapter photoAdapter;

public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Log.v(TAG, "on Activity Created ");

}

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

public void onAttach(Activity activity) {
    super.onAttach(activity);
    this.mContext …
Run Code Online (Sandbox Code Playgroud)

android gridview android-adapterview

6
推荐指数
1
解决办法
2万
查看次数

Android中的自定义adapterview setselection实现

我正在修改适配器视图.我如何实现setSelection()AdapterView?setSelection()调用adapterview的方法时必须采取哪些步骤?

我尝试浏览ListView's源代码,但它没有多大帮助.

android android-adapterview

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

具有更多ListView的AdapterView.OnItemClickListener

我在一个片段上有2个ListView,我想知道我是否可以为实现AdapterView.OnItemClickListener的同一个类设置.

我的意思是,Android文档说:

public abstract void onItemClick (AdapterView<?> parent, View view, int position, long id)

Added in API level 1
Callback method to be invoked when an item in this AdapterView has been clicked.

Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.

Parameters
parent  The AdapterView where the click happened.
view    The view within the AdapterView that was clicked (this will be a view provided by the adapter)
position    The position of the …
Run Code Online (Sandbox Code Playgroud)

android android-listview onclicklistener android-adapterview

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

自动滚动AdapterView(Listview,GridView,...)

背景

我正在尝试使用AdapterView(listview,gridview,...)来慢慢自动滚动.

用户可以随时切换它,并且不必一直移动到adapterView的末尾.

再次,我不希望让adapterView一直滚动到底部,因为用户应该可以取消自动滚动.

我试过的

为此,我正在使用下一个代码:

private static final SCROLLING_RUNNABLE = new Runnable() {

    @Override
    public void run() {
        final int duration = 10;
        final int pixelsToMove = 1;
        mAdapterView.smoothScrollBy(pixelsToMove, duration);
        mHandler.postDelayed(this, duration);
    }
};

...
// use this to turn auto-scrolling on:
mHandler.post(SCROLLING_RUNNABLE);
// use this to turn auto-scrolling off:
mHandler.removeCallbacks(SCROLLING_RUNNABLE);
Run Code Online (Sandbox Code Playgroud)

问题

代码通常有效,但在某些情况下,滚动开始需要很长时间.

事实上,似乎我越是开启和关闭,我就越需要等待它开始自动滚动.

我认为只有当我滚动回到顶部时才会出现此问题.当adapterView稍微滚动时,它工作得很好.

因为我无法找到如何获取adapterView的当前滚动值,我无法找到如何解决此问题.

这个问题

我该怎么做才能解决这个问题?还有其他选择吗?

android scroll android-listview android-gridview android-adapterview

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

android:stackFromBottom ="true"似乎不能正常工作(反向ListView与适配器)

好吧,让我解释一下"不能完美运作"的含义.

我有一个没有android:stackFromBottom="true"参数的listview .我也有一个常规的ArrayAdapter getItem(position).我打电话给我的网络服务器,获取asc日期订单的数据.

这样,列表中位置0(顶部)的项目具有最小的日期.我可以滚动顶部 - >底部.好.

我添加了android:stackFromBottom,现在我看到现在你可以从bottom-> top开始scolling但是位置0的项目仍然是顶级项目并且具有最小的日期.所以适配器没有改变它的顺序.

解决此问题的唯一方法是更改getItem(getCount()-1-position)适配器内部.但是我添加并通知适配器,适配器仍然会将项目添加到底部.

我猜结构是ListView -> Adapter -> Row Views如此无论stackFromBottom价值,只有一个孩子,适配器.对?

无论如何,如何使用适配器的ListView以相反的顺序?

android android-listview android-adapter android-adapterview

5
推荐指数
2
解决办法
6129
查看次数

如何在RecyclerView Adapter中添加固定Button?

nav_draw_row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true">

  <TextView
    android:id="@+id/title"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="30dp"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:textSize="15dp"
    android:textStyle="bold"
    android:focusable="true"
    android:outlineProvider="bounds" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

现在我想Button在 的末尾添加一个固定nav_draw_row,但是每当我在上面的代码中添加按钮时,就在TextView. 它以如下方式显示: 在此输入图像描述

我知道为什么会发生这种情况,但无法找到Button最终修复的解决方案Bar。这是我的Adapter代码:

public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.MyViewHolder> {

List<NavDrawerItem> data = Collections.emptyList();
private LayoutInflater inflater;
private Context context;

    public NavigationDrawerAdapter(Context context, List<NavDrawerItem> data) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.data = data;
    }

    public void delete(int position) {
        data.remove(position);
        notifyItemRemoved(position);
    }

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

android android-layout android-listview android-adapterview android-recyclerview

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

AdapterView 不支持 Android 8.1/9.0 removeView(View)

在 Android 8.1 和 9.0 版中运行我的应用程序时,出现“AdapterView 不支持removeView(View)”异常。在以前的版本中它运行良好。虽然错误是一致的,但它不会 100% 发生(这让我怀疑这是一个线程问题),也不是特定于特定适配器或列表视图。例如,我从多个活动访问相同的代码,它对某些人工作正常,但对其他人总是失败。我还应该指出,在出现错误的任何情况下,我都不会调用 removeView。以下是异常的 LogCat 输出:

java.lang.UnsupportedOperationException: removeView(View) is not supported in AdapterView
    at android.widget.AdapterView.removeView(AdapterView.java:531)
    at android.view.ViewOverlay$OverlayViewGroup.add(ViewOverlay.java:195)
    at android.view.ViewGroupOverlay.add(ViewGroupOverlay.java:72)
    at android.transition.TransitionUtils.createViewBitmap(TransitionUtils.java:170)
    at android.transition.TransitionUtils.copyViewImage(TransitionUtils.java:104)
    at android.transition.Visibility.onDisappear(Visibility.java:380)
    at android.transition.Visibility.createAnimator(Visibility.java:249)
    at android.transition.Transition.createAnimators(Transition.java:732)
    at android.transition.TransitionSet.createAnimators(TransitionSet.java:396)
    at android.transition.Transition.playTransition(Transition.java:1779)
    at android.transition.TransitionManager$MultiListener.onPreDraw(TransitionManager.java:315)
    at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2349)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
    at android.view.Choreographer.doCallbacks(Choreographer.java:723)
    at android.view.Choreographer.doFrame(Choreographer.java:658)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Run Code Online (Sandbox Code Playgroud)

任何人都可以指出我的解决方案吗?

android listview android-adapter android-adapterview

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