开发者

How to expand and show elements in a listview?

I have made a custom list view where each row has two textviews and a seek bar. I want to show initially only one text view and when the user clicks on an item the list should expand to full screen and show the textviews and seekbar.

This is what I have achieved until now:

public class ExpandableListActivity extends ListActivity
{
    Context context;
    private TextView mTitle;
    private TextView mDialogue;
    private SeekBar seekbar;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        context = this;
        // Use our own list adapter
        setListAdapter(new ListAdapter(this));
    }


    @Override
    protected void onListItemClick(ListView l, View v, int position, long id)
    {

    }


    private class ListAdapter extends BaseAdapter {
        public ListAdapter(Context context)
        {
            mContext = context;
        }

        public int getCount() {
            return mTitles.length;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            View rowView = inflater.inflate(R.layout.listlayout, null, true);
            mTitle = (TextView) rowView.findViewById(R.id.textView1);
            mDialogue= (TextView) rowView.findViewById(R.id.textView2);
            seekbar = (SeekBar)rowView.findViewById(R.id.seekBar1);
            mTitle.setText(mTitles[position]);
            mDialogue.setText(mDialogues[position]);

            return rowView;
        }

        private Context mContext;

        String [] mTitles = getResources().getStringArray(R.array.state_name);开发者_Python百科
        String [] mDialogues = getResources().getStringArray(R.array.capital_name);
    }
}


Use ExpandableListActivity or ExpandableListView. http://techdroid.kbeanie.com/2010/09/expandablelistview-on-android.html


It looks like you need to take a look at the ListView tutorial. Your getView() may work but its not very effective at using the existing API. Then implement onListItemClick(...) with the desired behavior. Additionally, as Kumar Bibek wrote, you may want to take a look at ExpandableListView.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜