Android的 - 是有办法的选项菜单添加到的listItem [英] Android - is there a way to add an options menu to a listItem

查看:111
本文介绍了Android的 - 是有办法的选项菜单添加到的listItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显示一些项目,如列表,我想知道是否有一个小的下拉添加到屏幕的右侧为列表中赋予删除/编辑选项的每个项目的方式。

I display some items as a list and I was wondering whether there was a way to add a little dropdown to the right of the screen for each item in the list giving the options of delete/edit.

这可能吗?现在分辩我列出这样的事情:

Is that possible? Rigth now I list things like this:

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


<include android:id="@+id/header"
         layout="@layout/header"
         android:layout_height="wrap_content"
         android:layout_width="fill_parent"/>    


<TextView
    android:id="@+id/no_problems"    
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Enter the business(es) you want to plan or choose from your existing list."
    />          


    <ListView
    android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label"
        android:textSize="20px" >        
    </ListView>

        <Button
    android:id="@+id/add_problem_ok"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/light_best_blue" 
    android:text="Plan a New Business"
    android:layout_marginTop ="15dp"    
    />  
</LinearLayout>

和ListView中我有这样的:

and in the listView I have this:

<?xml version="1.0" encoding="utf-8"?>

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="10dp"
        android:textSize="16sp" >
    </TextView>       

谢谢!

推荐答案

就在乌尔列表项目布局添加微调,然后将适配器getView到TAT微调与()方法。

Just add spinner in ur list item layout, then set adapter to tat spinner with in getView() method.

为前。 UR list_item.xml

for ex. ur list_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
 <TextView android:id="@+id/nameTV" android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:padding="10dp"
        android:textSize="16sp" >
    </TextView>  

<Spinner android:id="@+id/actionSP" android:layout_width="wrap_content"
        android:layout_height="fill_parent" />
</LinearLayout>

然后UR getView()

then UR getView()

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        final ViewHolder viewHolder;

        if (view == null) {
            viewHolder = new ViewHolder();

            view = mInflater.inflate(R.layout.list_item,
                    null);
            viewHolder.nameTV = (TextView) view
                    .findViewById(R.id.nameTV);

            viewHolder.actionSP = (Spinner) view
                    .findViewById(R.id.actionSP);

            ArrayAdapter<String> reasonAdapter = new ArrayAdapter<String>(
                    mApplication, android.R.layout.simple_spinner_item,
                    mYourActionsArray);

            reasonAdapter
                    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            viewHolder.actionSP.setAdapter(reasonAdapter);

            viewHolder.actionSP
                    .setOnItemSelectedListener(new OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> arg0,
                                View arg1, int position, long arg3) {
                        }
                    });
                view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.nameTV.setText("Some Value");

返回查看;
        }

return view; }

ViewHolder类

ViewHolder class

class ViewHolder {
    TextView nameTV;
    Spinner actionSP;
}

这篇关于Android的 - 是有办法的选项菜单添加到的listItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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