The click listener of the list view item with the [Android] button doesn't work.

Asked 2 years ago, Updated 2 years ago, 24 views

If I had a button in the list view item, I was told to give this focusable: "false", so I gave it to both buttons!

I can't click on the list view item 버튼 클릭 Button click listener is set in Adapter view!

<RelativeLayout
    android:descendantFocusability="blocksDescendants"
    android:id="@+id/listlayout"
    android:clickable="true"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="85dp">


    <Button
        android:id="@+id/progressend"
        android:text="end"
        android:focusableInTouchMode="false"
        android:focusable="false"
        android:clickable="false"
        android:background="@drawable/shape"
        android:textColor="@color/colorPrimary"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_alignTop="@+id/progressgo"
        android:layout_toRightOf="@+id/progressgo"
        android:layout_toEndOf="@+id/progressgo" />

    <Button
        android:text="confirm"
        android:focusableInTouchMode="false"
        android:focusable="false"
        android:clickable="false"
        android:id="@+id/progressgo"
        android:background="@drawable/shape_ok"
        android:textColor="@color/white"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/linearLayout"
        android:layout_toRightOf="@+id/linearLayout"
        android:layout_toEndOf="@+id/linearLayout" />

    <ProgressBar

        android:progressDrawable="@drawable/progressbar_custom"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="60dp"
        android:layout_marginRight="10dp"
        android:max="100"
        android:id="@+id/progressbar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:layout_below="@+id/linearLayout"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

Adapter.java

 public void bindView (View view, final context, Cursor cursors) {

        final ProgressBar progressbar =(ProgressBar)view.findViewById(R.id.progressbar);
        final Button btn_go =(Button)view.findViewById(R.id.progressgo);
        final Button btn_end =(Button)view.findViewById(R.id.progressend);
        final RelativeLayout layout = (RelativeLayout)view.findViewById(R.id.listlayout);
        btn_go.setFocusable(false);
        btn_end.setFocusable(false);
        progressbar.setFocusable(false);
        final int  num =cursor.getInt(cursor.getColumnIndex("count"));



        btn_go.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }

        });

        btn_end.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


            }
        });

        onContentChanged();

    }

From the fragment tab, I brought it as a listener's ancient style, which was well attached to other fragments like this, but it doesn't work. What's the problem?

Tab2.java

   mListView = (ListView) view.findViewById(R.id.list);
   mListView.setEmptyView(view.findViewById(R.id.emptyView));
                                        dbmanager = new DBManager(getActivity());

 mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    Toast.makeText(getView().getContext(), "Listview Clicklistener",
            Toast.LENGTH_SHORT).show();
    Context mContext = getActivity();
    cursor.moveToPosition(position);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.tab2_dialog, null);

    TextView text = (TextView) layout.findViewById(R.id.dialog_name);
    TextView date = (TextView) layout.findViewById(R.id.dialog_date);
    TextView step = (TextView) layout.findViewById (R.id.dialog_step); (omitted)`

android

2022-09-21 16:49

1 Answers

It's time for you to use RecyclerView instead of ListView


2022-09-21 16:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.