当前位置: 首页 > 知识库问答 >
问题:

Listview按钮单击处理

郁吉星
2023-03-14
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="false"
        android:layout_alignParentEnd="false">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/patient_info"
                android:id="@+id/textView"
                android:layout_alignParentTop="false"
                android:textSize="30sp"
                android:layout_alignParentLeft="false"
                android:layout_alignParentStart="false"
                android:layout_toLeftOf="@+id/button3"
                android:layout_toStartOf="@+id/button3"
                android:layout_marginRight="5dp"
                android:layout_gravity="center_vertical"
                android:layout_weight="1" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right">

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="right">

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/add"
                    android:id="@+id/button1"
                    android:layout_alignParentRight="false"
                    android:layout_alignParentEnd="false" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/sync"
                    android:id="@+id/button3"
                    android:layout_alignParentTop="false"
                    android:layout_toLeftOf="@+id/button1"
                    android:layout_toStartOf="@+id/button1" />
            </LinearLayout>

        </LinearLayout>

    </LinearLayout>


    <ProgressBar
        style="@android:style/Widget.Material.Light.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar2" />

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:ems="10"
            android:id="@+id/editText11"
            android:hint="Old Registration Number" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:ems="10"
            android:id="@+id/editText10"
            android:hint="New Registartion Number" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:ems="10"
            android:id="@+id/editText7"
            android:hint="Name" />

        <Button
            android:text="search"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button" />
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:text="SEARCH RESULTS"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView2"
            android:textSize="20sp"
            android:gravity="center"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp" />
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/listView"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

    </LinearLayout>

</LinearLayout>

如何处理ListView中的每个按钮单击?活动课

 String[] from = new String[]{DBHelper.ID, DBHelper.FNAME, DBHelper.LNAME, DBHelper.ADDRESS, DBHelper.REGID};
int[] to = new int[]{R.id.id,R.id.fname,R.id.lname,R.id.address,R.id.regid};
  adapter = new SimpleCursorAdapter(this, R.layout.list, cursor, from, to, 0);
  listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        //listview click event handling
            id = (TextView) arg1.findViewById(R.id.id);
            int id_To_Search = Integer.valueOf(id.getText().toString());

            Bundle dataBundle = new Bundle();
            dataBundle.putInt("_id", id_To_Search);

            Intent intent = new Intent(getApplicationContext(), AddPatient.class);

            intent.putExtras(dataBundle);
            startActivity(intent);
        }
    });

如何管理ListView中每个项目的按钮单击?我尝试了许多方法…如何解决此问题?请任何人帮帮我...

共有1个答案

程博学
2023-03-14
public View getView(final int position, View convertView,ViewGroup parent) 
{
   if(convertView == null)
   {
        LayoutInflater inflater = getLayoutInflater();
        convertView  = (LinearLayout)inflater.inflate(R.layout.YOUR_LAYOUT, null);
   }

   Button Button1= (Button)  convertView  .findViewById(R.id.BUTTON1_ID);

   Button1.setOnClickListener(new OnClickListener() 
   { 
       @Override
       public void onClick(View v) 
       {
           // Your code that you want to execute on this button click
       }

   });


   return convertView ;
}
 类似资料:
  • 帮助处理通过适配器在ListView中设置的按钮上的单击。 我重新阅读了很多网站,都考虑过类似的任务,但都无法弄清楚并在我的代码中实现,希望大家能帮助我。提前谢谢你。

  • 问题内容: 我在非Java和非Android领域拥有扎实的经验,正在学习Android。 我对不同领域有很多困惑,其中之一就是如何处理按钮单击。至少有4种方式(!!!),此处简要列出 为了保持一致性,我将列出它们: 在活动中具有该类的成员,并将其分配给将处理活动方法中的逻辑的实例。 在“ onCreate”活动方法中创建“ onClickListener”,然后使用setOnClickListen

  • 我想知道如何选择listview first item select并通过单击按钮自动单击。 使用下面的代码,我可以选择第一行,但无法选择。 这是我的listview点击事件: 非常感谢您的帮助!如果有人想了解更多信息,请务必告诉我,以便我更新我的问题。

  • 这是我的listview点击事件: 这是我的按钮点击事件: 现在,我需要获得单击的listview项的位置。我已经声明了全局位置,但这总是给我位置1。 有人能告诉我怎么得到这个职位吗?

  • 我正试图抓取一个页面,获取一盘国际象棋的移动列表,该列表位于右侧菜单的“移动”选项卡下。 在浏览器中手动单击“移动”选项卡时,我可以通过 哪个(正确地)返回 当尝试通过单击按钮时,使用 似乎什么都没有发生,我不知道如何进行故障排除。 如何通过模拟单击(活动事件侦听器)切换到“移动”选项卡? 额外提示:是否可以使用rvest软件包?

  • 问题内容: 我正在尝试在www.meetme.com上发送消息,但不知道该怎么做。我可以在评论区域中键入消息,但是单击“发送”按钮不会执行任何操作。我究竟做错了什么?当我登录并按登录按钮时,页面确实发生了变化,一切都很好。有人有任何想法或线索吗? 问题答案: 如果不了解正在访问的网页,就无法在禁用JavaScript的情况下执行AJAX请求。如果更改未成功,则必须继续进行调试,但请确保已启用Jav