Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Up.setVisibility(View.VISIBLE);不显示按钮_Android_Button - Fatal编程技术网

Android Up.setVisibility(View.VISIBLE);不显示按钮

Android Up.setVisibility(View.VISIBLE);不显示按钮,android,button,Android,Button,我用的是碎片加上折射。其中有6个按钮-编辑、添加、删除、上、下、上。当屏幕第一次显示时,显示编辑、添加、删除按钮,而向上、向下和向后按钮不可见。当我按下“添加”按钮时,“上”、“下”、“下”按钮应可见,而“编辑”、“添加”、“删除”按钮不应可见。但当我按下按钮时,所有其他按钮都不可见。 代码: 公共类PlusOneFragment扩展片段{ //TODO:重命名参数参数,选择匹配的名称 //片段初始化参数,例如ARG_ITEM_NUMBER 私有静态最终字符串ARG_PARAM1=“PARAM1

我用的是碎片加上折射。其中有6个按钮-编辑、添加、删除、上、下、上。当屏幕第一次显示时,显示编辑、添加、删除按钮,而向上、向下和向后按钮不可见。当我按下“添加”按钮时,“上”、“下”、“下”按钮应可见,而“编辑”、“添加”、“删除”按钮不应可见。但当我按下按钮时,所有其他按钮都不可见。 代码:

公共类PlusOneFragment扩展片段{
//TODO:重命名参数参数,选择匹配的名称
//片段初始化参数,例如ARG_ITEM_NUMBER
私有静态最终字符串ARG_PARAM1=“PARAM1”;
私有静态最终字符串ARG_PARAM2=“PARAM2”;
//TODO:重命名和更改参数类型
私有字符串mParam1;
私有字符串mParam2;
静态上下文;
静态列表停止;
静态整数计数_停止;
按钮编辑、添加、删除、向上、向下、向后;
字符串对话框结果;
静态停止活动obj;
公共PlusOneFragment(上下文c、整数计数\u stopsArg、列表stopsArg、StopActivity参数){
//必需的空公共构造函数
cntxt=c;
计数停止=计数停止;
停止=停止器;
obj=Arg;
}
/**
*使用此工厂方法创建的新实例
*使用提供的参数创建此片段。
*
*@param param1参数1。
*@param param2参数2。
*@return一个fragment PlusOneFragment的新实例。
*/
//TODO:重命名和更改参数的类型和数量
公共静态PlusOneFragment newInstance(字符串param1,字符串param2){
PLUSONEFRAGENT片段=新的PLUSONEFRAGENT(cntxt,计数\停止,停止,obj);
Bundle args=新Bundle();
args.putString(ARG_PARAM1,PARAM1);
args.putString(ARG_PARAM2,PARAM2);
fragment.setArguments(args);
返回片段;
}
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
如果(getArguments()!=null){
mParam1=getArguments().getString(ARG_PARAM1);
mParam2=getArguments().getString(ARG_PARAM2);
}
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//为该碎片膨胀布局
视图=充气机。充气(R.layout.fragment_first,container,false);
//TextView tv=(TextView)view.findViewById(R.id.seat\u serial\u前缀);
//tv.setText(“yourText”);
编辑=(按钮)视图.findViewById(R.id.btn\u编辑);
Add=(按钮)view.findViewById(R.id.btn\u Add);
Delete=(按钮)view.findviewbyd(R.id.btn\u Delete);
Up=(按钮)view.findViewById(R.id.btn\u Up);
Bottom=(按钮)view.findViewById(R.id.btn_Bottom);
Back=(按钮)view.findViewById(R.id.btn\u Back);
Up.setVisibility(View.GONE);
Bottom.setVisibility(View.GONE);
Back.setVisibility(View.GONE);
RadioGroup RadioGroup=(RadioGroup)视图.findViewById(R.id.RadioGroup);
//添加每个单选按钮时要使用的布局参数
LinearLayout.LayoutParams LayoutParams=新的RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_内容,
RadioGroup.LayoutParams.WRAP_内容);
//向组中添加20个单选按钮
对于(int u=0;u
xml:



改变这一点解决了问题

public class PlusOneFragment extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    static Context cntxt ;
    static List<String> Stops;
    static int count_stops;
    Button Edit, Add, Delete, Up, Bottom, Back;
    String DialogResult;
    static StopActivity obj;
    public PlusOneFragment(Context c, int count_stopsArg, List<String>  StopsArg, StopActivity Arg) {
        // Required empty public constructor
        cntxt = c;
        count_stops = count_stopsArg;
        Stops = StopsArg;
        obj = Arg;
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment PlusOneFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static PlusOneFragment newInstance(String param1, String param2) {
        PlusOneFragment fragment = new PlusOneFragment(cntxt, count_stops, Stops, obj);
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_first, container, false);
        //TextView tv= (TextView) view.findViewById(R.id.seat_serial_prefix);
        //tv.setText("yourText");
        Edit = (Button) view.findViewById(R.id.btn_edit) ;
        Add = (Button) view.findViewById(R.id.btn_add) ;
        Delete = (Button) view.findViewById(R.id.btn_delete) ;
        Up = (Button) view.findViewById(R.id.btn_up) ;
        Bottom = (Button) view.findViewById(R.id.btn_bottom) ;
        Back = (Button) view.findViewById(R.id.btn_back) ;
        Up.setVisibility(View.GONE);
        Bottom.setVisibility(View.GONE);
        Back.setVisibility(View.GONE);
        RadioGroup radiogroup = (RadioGroup) view.findViewById(R.id.radiogroup);
        // layout params to use when adding each radio button
        LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
                RadioGroup.LayoutParams.WRAP_CONTENT,
                RadioGroup.LayoutParams.WRAP_CONTENT);
        // add 20 radio buttons to the group
        for (int u = 0; u < count_stops; u++) {
            RadioButton newRadioButton = new RadioButton(cntxt);
            String label = Stops.get(u);
            newRadioButton.setText(label);
            newRadioButton.setId(u);
            radiogroup.addView(newRadioButton, layoutParams);
        }
Add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Up.setVisibility(View.VISIBLE);
                Bottom.setVisibility(View.VISIBLE);
                Back.setVisibility(View.VISIBLE);
                Add.setVisibility(View.GONE);
                Edit.setVisibility(View.GONE);
                Delete.setVisibility(View.GONE);
            }

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

    <ScrollView
        android:id="@+id/scrollview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        >
        <LinearLayout
            android:id="@+id/linearMain"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >
            <TextView
                android:id="@+id/HTTPResult"
                android:text="Result"
                android:layout_width="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="10dp"
                android:layout_height="wrap_content" />
            <RadioGroup
                android:id="@+id/radiogroup"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                >
            </RadioGroup>
        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:id="@+id/linlayoutButtons"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        >
        <LinearLayout
            android:id="@+id/linlayoutButtons2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            >
                <Button
                    android:id="@+id/btn_edit"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="10dp"
                    android:text="Edit"
                    android:layout_weight="1"
                    >
                </Button>
                <Button
                    android:id="@+id/btn_delete"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="10dp"
                    android:text="Delete"
                    android:layout_weight="1"
                    >
                </Button>
                <Button
                    android:id="@+id/btn_add"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="10dp"
                    android:text="Add"
                    android:layout_weight="1"
                    >
                </Button>
        </LinearLayout>
            <LinearLayout
                android:id="@+id/linlayoutButtons3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                >
                <Button
                    android:id="@+id/btn_bottom"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="bottom"
                    android:layout_weight="1"
                    android:layout_marginRight="10dp"
                    >
                </Button>
                <Button
                    android:id="@+id/btn_up"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Up"
                    android:layout_weight="1"
                    android:layout_marginRight="10dp"
                    >
                </Button>
                <Button
                    android:id="@+id/btn_back"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Back"
                    android:layout_weight="1"
                    android:layout_marginRight="10dp"
                    >
                </Button>
            </LinearLayout>
    </LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/linlayoutBase"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >

    <ScrollView
        android:id="@+id/scrollview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        >
        <LinearLayout
            android:id="@+id/linearMain"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >
            <TextView
                android:id="@+id/HTTPResult"
                android:text="Result"
                android:layout_width="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="10dp"
                android:layout_height="wrap_content" />
            <RadioGroup
                android:id="@+id/radiogroup"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                >
            </RadioGroup>


            <LinearLayout
                android:id="@+id/linlayoutButtons2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                >
                    <Button
                        android:id="@+id/btn_edit"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:text="Edit"
                        android:layout_weight="1"
                        >
                    </Button>
                    <Button
                        android:id="@+id/btn_delete"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:text="Delete"
                        android:layout_weight="1"
                        >
                    </Button>
                    <Button
                        android:id="@+id/btn_add"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:text="Add"
                        android:layout_weight="1"
                        >
                    </Button>
                <Button
                    android:id="@+id/btn_done"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Done"
                    android:layout_weight="1"
                    >
                </Button>
            </LinearLayout>
                <LinearLayout
                    android:id="@+id/linlayoutButtons3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:layout_marginTop="20dp"
                    >
                    <Button
                        android:id="@+id/btn_bottom"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="bottom"
                        android:layout_weight="1"
                        android:layout_marginRight="10dp"
                        >
                    </Button>
                    <Button
                        android:id="@+id/btn_up"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Up"
                        android:layout_weight="1"
                        android:layout_marginRight="10dp"
                        >
                    </Button>
                    <Button
                        android:id="@+id/btn_back"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Back"
                        android:layout_weight="1"
                        android:layout_marginRight="10dp"
                        >
                    </Button>
                </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>