0

我在我的项目中使用以下列表视图和列表项。如果我加载项目,则第一个相对布局仅可见,而第二个相对布局(三个按钮)对于所有列表项都不可见,当我单击一个列表项时,它会显示第二个相对布局项目(三个按钮),然后单击第二个列表项,已经打开的第一个列表项(三个按钮)不可见。现在可单击的列表项通过三个按钮可见。它的工作方式类似于可展开的列表视图折叠项目,请任何人帮助我。 ..

在我的列表视图中:

<ListView
    android:id="@+id/frontpagetasklistid"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
</ListView>

列表视图项目:

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

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
        <TextView
            android:id="@+id/tasknameidDaytoDay"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

            <ImageButton
                android:layout_alignParentRight="true"
                android:id="@+id/imagebuttonidDaytoDay"
                android:layout_width="31dp"
                android:layout_height="46dp"
                android:layout_gravity="center_vertical"
                android:background="@drawable/editors"
                android:clickable="true"
                android:onClick="editButtonClick" >
            </ImageButton>
        </RelativeLayout>
        <RelativeLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            >
            <LinearLayout 
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:weightSum="3"
                >

        <Button
            android:id="@+id/taskTimeidDaytoDay"
            android:layout_width="0dip"
            android:background="@drawable/buttonselector"
            android:layout_height="35dp" 
            android:textSize="15dip"
            android:layout_weight="1"/>

        <Button
            android:id="@+id/severityidDaytoDay"
            android:layout_width="0dip"
            android:background="@drawable/buttonselector"
            android:layout_height="35dp" 
            android:textSize="15dip"
            android:layout_weight="1"/>

        <Button
            android:id="@+id/alarmidDaytoDay"
            android:layout_width="0dip"
            android:layout_height="35dp" 
            android:background="@drawable/buttonselector"
            android:textSize="15dip"
            android:layout_weight="1"/>

        </LinearLayout>
        </RelativeLayout>

    </LinearLayout>

在我的适配器中

package com.capsone.testing.calendar;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

public class DaytoDayTaskAdapter extends ArrayAdapter<DaytoDayTaskGetterSetter> {



    private final String TAG = "CalendarViewSample:"
            + this.getClass().getName();
    Context context;
    DaytoDayTaskGetterSetter objDaytoDaygetset;
    TextView textviewAlarm,textviewTask;
    ImageButton imagebtnDaytoDaytask;
    Button buttonAlarm,buttonTaskTime,buttonSeverity;
    List<DaytoDayTaskGetterSetter> arraylist=new ArrayList<DaytoDayTaskGetterSetter>();
    List<DaytoDaytaskListenerInterface> listDaytoDayTaskListener=new ArrayList<DaytoDaytaskListenerInterface>();

    public DaytoDayTaskAdapter(Context context, int textViewResourceId,List<DaytoDayTaskGetterSetter> arraylist)
    {
        super(context, textViewResourceId,arraylist);
        this.context=context;
        this.arraylist=arraylist;
        Log.i(TAG,"Listitems:"+this.arraylist.toString());
    }
    public void Register(DaytoDaytaskListenerInterface editableDaytoDayTask) 
    {
        listDaytoDayTaskListener.add(editableDaytoDayTask);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
         final DaytoDayTaskGetterSetter objDaytoDaygetset=getItem(position);
         LayoutInflater inflater=(LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
         if(convertView==null)
         {
             convertView=inflater.inflate(R.layout.daytodaylistlayout,null);
             textviewTask=(TextView)convertView.findViewById(R.id.tasknameidDaytoDay);
             imagebtnDaytoDaytask=(ImageButton)convertView.findViewById(R.id.imagebuttonidDaytoDay);
             buttonAlarm=(Button)convertView.findViewById(R.id.alarmidDaytoDay);
             buttonSeverity=(Button)convertView.findViewById(R.id.severityidDaytoDay);
             buttonTaskTime=(Button)convertView.findViewById(R.id.taskTimeidDaytoDay);
             imagebtnDaytoDaytask.setFocusable(false);
             buttonAlarm.setFocusable(false);
             buttonSeverity.setFocusable(false);
             buttonTaskTime.setFocusable(false);
         }

         textviewTask.setText(objDaytoDaygetset.getTask());
         buttonAlarm.setText(objDaytoDaygetset.getAlarm());
         buttonSeverity.setText(objDaytoDaygetset.getStatusSeverity());
         buttonTaskTime.setText(objDaytoDaygetset.getTaskTime());
         buttonAlarm.setVisibility(convertView.INVISIBLE);
         buttonSeverity.setVisibility(convertView.INVISIBLE);
         buttonTaskTime.setVisibility(convertView.INVISIBLE);
         buttonTaskTime.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


                for(DaytoDaytaskListenerInterface objDaytoDaytask:listDaytoDayTaskListener)
                {
                    Bundle bundle=new Bundle();
                    String taskName=objDaytoDaygetset.getTask();
                    String taskTime=objDaytoDaygetset.getTaskTime();

                    bundle.putString("TASK_NAME",taskName);
                    bundle.putString("TASK_TIME", taskTime);
                    objDaytoDaytask.EditDaytoDayTaskTime(bundle);
                }

            }
        });
         buttonSeverity.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                for(DaytoDaytaskListenerInterface objDaytoDaytask:listDaytoDayTaskListener)
                {
                    Bundle bundle=new Bundle();
                    String taskName=objDaytoDaygetset.getTask();
                    bundle.putString("TASK_NAME",taskName);
                    objDaytoDaytask.EditDaytoDaySeverity(bundle);
                }

            }
        });
        buttonAlarm.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                for(DaytoDaytaskListenerInterface objDaytoDaytask:listDaytoDayTaskListener)
                {
                    Bundle bundle=new Bundle();
                    String taskName=objDaytoDaygetset.getTask();
                    bundle.putString("TASK_NAME",taskName);
                    objDaytoDaytask.EditDaytoDayAlarm(bundle);
                }

            }
        });

        imagebtnDaytoDaytask.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                for(DaytoDaytaskListenerInterface objDaytoDaytask:listDaytoDayTaskListener)
                {
                    Bundle bundle=new Bundle();
                    String taskName=objDaytoDaygetset.getTask();
                    Log.i(TAG,"TAskNamecheckit"+taskName);
                    bundle.putString("TASKDAYTODAY",taskName);
                    objDaytoDaytask.EditDaytoDayTask(bundle);
                }



            }
        });
         return convertView;
    }

}

在我的主要活动 OnItemclick 中:

@Override
   public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

        Button
        buttonTaskTime=(Button)arg1.findViewById(R.id.taskTimeidDaytoDay);
        Button
        buttonSeverity=(Button)arg1.findViewById(R.id.severityidDaytoDay);
        Button buttonAlarm=(Button)arg1.findViewById(R.id.alarmidDaytoDay);

        buttonAlarm.setVisibility(arg1.VISIBLE);
        buttonSeverity.setVisibility(arg1.VISIBLE);
        buttonTaskTime.setVisibility(arg1.VISIBLE); 
}
4

0 回答 0