使用ArrayAdapter在ListActivity搜索栏 [英] SeekBar in a ListActivity using an ArrayAdapter

查看:274
本文介绍了使用ArrayAdapter在ListActivity搜索栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不依赖于使用ArrayAdapter,但我要的是每个项目包含一个ImageView的,一个TextView和一个搜索栏在那里我可以更新图像/文本以及来自各滑块接收回​​调列表(显然,我需要能够添加和动态删除行)。

I'm not tied to using an ArrayAdapter but, what I want is a list where each item contains an ImageView, a TextView, and a SeekBar to where I can update the images/texts as well as receive callbacks from each slider (obviously, I need to be able to add and delete rows dynamically).

我不麻烦创建包含这些项目是静态列表 - >即在XML布局我的列表中的每一行定义。然而,与此,我无法覆盖'onStartTrackingTouch()','onProgressChanged()'等回调方法。我还可以创建一个列表仅包含seekbars,我可以得到回调。当我在LayoutInflater带来,然后尝试我seekbars添加到布局的问题。

I've no trouble creating a list that contains these items that is static -> i.e. defined in an xml layout for each row of my list. However, with this, I'm unable to "overwrite the 'onStartTrackingTouch()', 'onProgressChanged()', etc. callback methods". I also can create a list that "contains only seekbars" and I can get the callbacks. The problem is when I bring in the LayoutInflater and then try to add my seekbars to the layout.

在它周围碴和互联网上搜索的几天里,我依然看不到解决有使用layoutinflator创建包含一个ImageView的,TextView的复合列表行的listactivity和搜索栏,我可以与正常通信。

After several days of mucking around with it and searching on the internet, I still can't see a solution to have a listactivity that uses a layoutinflator to create composite list rows consisting of an imageview, textview, and seekbar that I can communicate properly with.

有没有人有办法解决吗? code?

Does anyone have a solution? Code?

我已经得到了到目前为止是这样的东西:

What I've got so far goes something like:

public class MyListActivity extends ListActivity
{   
    private class MyView {
        public ImageView myImageView = null;
        public TextView myTextView = null;
        public SeekBar mySeekBar = null;        
    }

  private class MyAdapter extends ArrayAdapter<MyView> {                
    private ArrayList<MyView> arrayList;
    private MyListActivity theContext = null;

    public MyAdapter(MyListActivity context, 
                  int textViewResourceId,
                  ArrayList<MyView> arrayListPassedIn) {
        super(context, textViewResourceId, arrayListPassedIn);
        this.volumeControls = arrayListPassedIn;
        theContext = context;
    } 

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;

        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);                
            v = vi.inflate(R.layout.dont_think_i_should_need_to_use_a_resource_here_cuz_it_should_be_generated_or_dynamic, parent, false);
        }

        arrayList.get(position).myImageView = new ImageView(theContext);
        arrayList.get(position).myImageView.setBackgroundResource(R.drawable.generic_image);

        if(position == 0)
        {   
            arrayList.get(position).mySeekBar = new SeekBar(theContext);        
            arrayList.get(position).mySeekBar.setMax(100);
            arrayList.get(position).mySeekBar.setEnabled(true);
            arrayList.get(position).mySeekBar.setOnSeekBarChangeListener(
                new SeekBar.OnSeekBarChangeListener() {                         
                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                        Log.d("test", "0th seekbar touched");                
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                        Log.d("test", "0th seekbar touch lifted");
                    }

                    @Override
                    public void onProgressChanged(SeekBar seekBar, int arg1, boolean fromUser) {
                        Log.d("test", "0th seekbar progress changed");                                         
                    }
                }
            );                                  
        }
        else
        {               
            arrayList.get(position).mySeekBar = new SeekBar(theContext);        
            arrayList.get(position).mySeekBar.setMax(100);
            arrayList.get(position).mySeekBar.setEnabled(true);
            arrayList.get(position).mySeekBar.setOnSeekBarChangeListener(
                new SeekBar.OnSeekBarChangeListener() {                         
                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                        Log.d("test", "*not* 0th seekbar touched");                
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                        Log.d("test", "*not* 0th seekbar touch lifted");
                    }

                    @Override
                    public void onProgressChanged(SeekBar seekBar, int arg1, boolean fromUser) {
                        Log.d("test", "*not* 0th seekbar progress changed");                                           
                    }
                }
            );
        }

        //***this is the fuzzy part -> I need to be able to obtain the layout for the 'parent ViewGroup' or something
        //to where I can somehow add my seekbar (and textview and imageview) and then return the 'parent view'
        //that is to say that, this method is required to return a View and I want to return a View that composits
        //my imageview, textview, and seekbar.  One main problem seems to be that an ArrayAdapter won't allow me to add
    //child views dynamically.
        final View viewToAdd = arrayList.get(position). mySeekBar;            
        LinearLayout layout = ???;//new LinearLayout(theContext);             
        layout.post(new Runnable() {
            public void run() {
                layout.addView(viewToAdd);
                layout.destroyDrawingCache();
                layout.buildDrawingCache();
            }
        });

      return ???;   //layout.view??  Can I obtain the 'parent view' (the view for the entire row) somehow to return?
    }        
}

private ArrayList<MyView> myArrayList;
    private MyAdapter myAdapter;

@Override
    public void onCreate(Bundle savedInstanceState) {
    try {           
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_for_the_list_activity_all_it_contains_is_a_linearlayout_containing_the_listview);
        myArrayList = new ArrayList<MyView>();
        myArrayList.add(new MyView());
        myArrayList.add(new MyView());
            mAdapter = new SettingsListViewArrayAdapter(this, R.layout.wtf_not_sure_what_I_should_put_here, this.myArrayList);
            setListAdapter(mAdapter);           
    } catch (NullPointerException e) {
        Log.v(getString(R.string.app_name), e.getMessage());
    }
  } 
}

对于所有我知道我wayyy偏离轨道。从外观上来看,它甚至没有可能呢?有人请帮助! (感谢事先= -D)

For all I know I'm wayyy off track. From the looks of it, it's not even possible? Someone please help!? (and thanks in advance =-D )

P.S。我真的不关心如何解决这个问题,我只是需要有一个'动态调整大小列表,其中每个项目包含一个ImageView的,TextView的,和搜索栏,并在那里我可以修改每接收回调为每个单独的搜索栏。 (如果解秤,这将是很酷,但肯定不是作为列表可能会通常只含有少于20项的要求)

P.S. I really don't care how to solve the problem, I just need to have a 'dynamically resizeable' list where each item contains an imageview, textview, and seekbar and to where I can modify each and receive callbacks for each individual seekbar. (if the solution scales, that would be cool but, most certainly not a requirement as the list will likely usually only contain less than 20 items)

推荐答案

好吧,我觉得我终于想通了(难道你不知道,不久后这个职位)。使用指南:: http://www.vogella.com/tutorials/AndroidListView/ article.html#listsactivity 的它看起来像它的工作了。

Okay, I think I finally figured it out (wouldn't you know it, shortly after this post). Using the guide at: http://www.vogella.com/tutorials/AndroidListView/article.html#listsactivity it seems like it's working now.

这篇关于使用ArrayAdapter在ListActivity搜索栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆