0

I am facing an issue in my application is that when i add a Button bottom of my ListView in android it's onItemClick doesn't work i am unable to click any item of ListView. For reference i am providing codes below : -

Custom Adapter Class :

Context context;

   String [] Heading= {"Triceps"};

    String [] Subheading= {"Triceps the essintial part of an exercise it will increase you muscle power..."};

    int [] gif = {R.drawable.triceps };

    public custom_adapter(Context ctx) {
        this.context=ctx;
    }
    @Override
    public int getCount() {
        return Heading.length;
    }
    @Override
    public Object getItem(int position) {
        return Heading[position];
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View view, ViewGroup parent) {
        if(view==null){
            LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view=inflater.inflate(R.layout.customlayout,null);
        }
        ImageView imageView=(ImageView) view.findViewById(R.id.imgId);
        TextView view1=(TextView) view.findViewById(R.id.Heading);
        TextView view2=(TextView) view.findViewById(R.id.Subheading);
        imageView.setImageResource(gif[position]);
        view1.setText(Heading[position]);
        view2.setText(Subheading[position]);
        return view;

    }}

Main Java class :

ListView listView;
    Button btn_start;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListView) findViewById(R.id.list);

        custom_adapter adapter = new custom_adapter(this);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {


            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(getApplicationContext(), workout_detail.class);
                intent.putExtra("Position", position);
                startActivity(intent);
            }
        });

        btn_start = (Button) findViewById(R.id.btn_start);

        btn_start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
}}

Xml file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity"
    android:background="#abf5f5">

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="650dp"
        android:background="#abf5f5"/>

    <Button
        android:id="@+id/btn_start"
        android:layout_marginTop="8dp"
        android:layout_width="match_parent"
        android:layout_below="@+id/list"
        android:layout_height="65dp"
        android:text="Start Workout"
        android:background="#40f716"/>

</RelativeLayout>

Help me out of this. Thanks in Advance.

Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53

1 Answers1

0

Okay! I have found the answer actually the user have to delete any button in custom layout if any and use the linear layout or constraint layout