Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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
Java 图像视图上未调用setOnClickListener_Java_Android_Imageview_Onclicklistener - Fatal编程技术网

Java 图像视图上未调用setOnClickListener

Java 图像视图上未调用setOnClickListener,java,android,imageview,onclicklistener,Java,Android,Imageview,Onclicklistener,我想在单击下一个图像视图时调用一个片段。所以我把OnClickListener放在图像视图上,但根本没有调用它 有什么问题吗 GoSend xml布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:tools="

我想在单击下一个图像视图时调用一个片段。所以我把OnClickListener放在图像视图上,但根本没有调用它

有什么问题吗

GoSend xml布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:fitsSystemWindows="true"
    android:id="@+id/LinearLayoutGoSend">
    <android.support.v7.widget.Toolbar
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        />
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@android:color/white"
    android:layout_marginLeft="15dp"
    android:layout_marginTop="10dp"
    android:layout_marginRight="15dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/DriversNear"
        android:id="@+id/textView10"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp" />


    <fragment android:layout_width="match_parent"
        android:layout_height="250dp"
        android:id="@+id/map"
        tools:context=".GoSend"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_marginTop="10dp" />

    </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_weight="1.00"
                android:background="@android:color/white"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:text="@string/From"
                    android:id="@+id/textView11"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="10dp" />

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="08dp"
                    android:id="@+id/imageView11"
                    android:background="@drawable/line2"/>

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

                    <ImageView
                        android:layout_width="25dp"
                        android:layout_height="25dp"
                        android:id="@+id/imageView10"
                        android:layout_marginLeft="20dp"
                        android:background="@drawable/ic_place_black_48dp"
                        android:layout_marginTop="05dp" />

                    <EditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/editText_from"
                        android:text="@string/Loc"
                        android:visibility="visible"
                        android:drawableRight="@drawable/ic_chevron_right_black_24dp"
                        android:layout_marginRight="10dp"
                        android:cursorVisible="false"/>

                </LinearLayout>

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

                    <ImageView
                        android:layout_width="25dp"
                        android:layout_height="25dp"
                        android:id="@+id/imageView12"
                        android:layout_marginLeft="20dp"
                        android:background="@drawable/ic_description_black_48dp"
                        android:layout_marginTop="05dp" />

                    <EditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/editText_from_details"
                        android:layout_marginRight="10dp"
                        android:hint="Location details"
                        android:cursorVisible="true"/>


                </LinearLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:id="@+id/textView12"
                    android:layout_marginLeft="48dp"
                    android:hint="House no./Floor/Landmark" />

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/LinearLayoutAdditionalContactFrom">

                    <ImageView
                        android:layout_width="25dp"
                        android:layout_height="25dp"
                        android:id="@+id/imageView13"
                        android:layout_marginLeft="20dp"
                        android:background="@drawable/ic_person_black_48dp"
                        android:layout_marginTop="05dp"
                        />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/contactDetailsFrom"
                        android:layout_marginRight="10dp"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:drawableRight="@drawable/ic_expand_more_black_24dp"
                        android:text="@string/additionalContact"
                        android:layout_gravity="center_vertical"
                        android:layout_marginTop="05dp"
                        android:layout_marginLeft="05dp" />
                </LinearLayout>


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:id="@+id/textView13"
                    android:layout_marginLeft="48dp"
                    android:hint="Input if you're not sender" />

            </LinearLayout>


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:id="@+id/textView15"
                    android:layout_marginLeft="48dp"
                    android:hint="House no./Floor/Landmark" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:id="@+id/textView16"
                        android:layout_marginLeft="48dp"
                        android:hint="input if you're not receiver" />
                </LinearLayout>

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:background="@android:color/white"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_weight="1.00">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:text="@string/Details"
                    android:id="@+id/textView17"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="10dp"
                    />

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="08dp"
                    android:id="@+id/imageView16"
                    android:background="@drawable/line2"/>
                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:layout_width="25dp"
                        android:layout_height="25dp"
                        android:id="@+id/imageView"
                        android:layout_marginLeft="20dp"
                        android:background="@drawable/ic_check_circle_black_48dp"
                        android:layout_marginTop="05dp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/pickup"
                        android:id="@+id/textView18"
                        android:layout_marginLeft="10dp"
                        android:layout_marginTop="05dp" />

                </LinearLayout>

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

                    <ImageView
                        android:layout_width="25dp"
                        android:layout_height="25dp"
                        android:id="@+id/imageView20"
                        android:layout_marginLeft="20dp"
                        android:background="@drawable/box5"
                        android:layout_marginTop="05dp" />

                    <EditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/editText_pac"
                        android:layout_marginRight="10dp"
                        android:hint="Items to deliver"/>

                </LinearLayout>
        </LinearLayout>
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView_next"
                android:layout_gravity="center_horizontal"
                android:layout_weight="0.42"
                android:clickable="true"
                android:background="@drawable/ic_chevron_right_black_48dp" />
        </LinearLayout>

    </ScrollView>

</LinearLayout>
GoSend活动

public class GoSend extends AppCompatActivity {

private GoogleMap mMap;
private MarkerOptions markerOptions;
private LinearLayout ll;
private TextView additionalContactFrom;
private TextView additionalContactTo;
private LinearLayout linearLayoutFrom;
private LinearLayout linearLayoutTo;
private ImageView next;

private Toolbar toolbar;
private EditText editTextLocation;
private EditText edtxt_from;
private EditText edtxt_to;
private String stringAddress;
String stringAddress1;
String stringAddressTo;
EditText locdetailsFrom;
EditText locdetailsTo;
private Intent i;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gosendlayout);

    setUI();

    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
    }

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}

public void setUI() {

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("COURIER");
    setSupportActionBar(toolbar);
   getSupportActionBar().setDisplayHomeAsUpEnabled(true);


    edtxt_from=(EditText)findViewById(R.id.editText_from);
    edtxt_to=(EditText)findViewById(R.id.editText_to);
    locdetailsFrom = (EditText) findViewById(R.id.editText_from_details);
    locdetailsTo = (EditText) findViewById(R.id.editText_to_details);
    additionalContactFrom = (TextView)findViewById(R.id.contactDetailsFrom);
    additionalContactTo = (TextView)findViewById(R.id.contactDetailsTo);
    linearLayoutFrom = (LinearLayout)findViewById(R.id.LinearLayoutFrom);
    linearLayoutTo = (LinearLayout)findViewById(R.id.LinearLayoutTo);
    next = (ImageView)findViewById(R.id.imageView_next);
    next.setClickable(true);

    try {
        if (mMap == null) {
            mMap = ((MapFragment) getFragmentManager().
                    findFragmentById(R.id.map)).getMap();
        }
        mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
        mMap.setMyLocationEnabled(true);
    } catch (Exception e) {
        e.printStackTrace();
    }

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

             i=new Intent(getApplicationContext(),PickLocationActivity.class);
            startActivity(i);
        }
    });

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

            i=new Intent(getApplicationContext(),PickLocationActivity.class);
            startActivity(i);
        }
    });


    additionalContactFrom.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if(linearLayoutFrom.getVisibility() == View.GONE){

                linearLayoutFrom.setVisibility(View.VISIBLE);

            }else{
              linearLayoutFrom.setVisibility(View.GONE);

            }
        }
    });


    additionalContactTo.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if(linearLayoutTo.getVisibility() == View.GONE){

                linearLayoutTo.setVisibility(View.VISIBLE);

            }else{
              linearLayoutTo.setVisibility(View.GONE);

            }
        }
    });

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

            DetailsFragment fragment = new DetailsFragment();
            FragmentManager fragmentManager = getSupportFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.LinearLayoutGoSend, fragment).commit();

        }
    });
}

@Override
public void onResume() {
    super.onResume();  // Always call the superclass method first
    Bundle bundle = getIntent().getExtras();
    if(bundle != null)
        stringAddress  = bundle.getString("address");

}
}

细节碎片

public class DetailsFragment extends Fragment {
    private Toolbar toolbar;
    public DetailsFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        View view = inflater.inflate(R.layout.fragment_details, container, false);

        return view;
    }

}
片段布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal|top"
    android:background="@android:color/transparent">
    <android.support.v7.widget.Toolbar
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        />
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@android:color/white"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/Details"
            android:id="@+id/textView22"
            android:layout_gravity="center_vertical"
            android:layout_marginTop="15dp"
            android:layout_marginStart="15dp" />
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:background="@android:color/white"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="20dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/payment"
            android:id="@+id/textView24"
            android:layout_marginStart="15dp"
            android:layout_marginTop="15dp" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="08dp"
            android:id="@+id/imageView23"
            android:background="@drawable/line2"
            android:layout_marginTop="10dp" />


        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:background="@android:color/white"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:weightSum="1">

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:id="@+id/imageView24"
                android:background="@drawable/coins49"
                android:layout_marginStart="10dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/price"
                android:id="@+id/textView25"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="10dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:id="@+id/textView26"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="190dp" />

            </LinearLayout>
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="08dp"
                android:id="@+id/imageView26"
                android:background="@drawable/line2"
                android:layout_marginTop="05dp" />


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp">

        <ImageView
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:id="@+id/imageView25"
            android:layout_marginStart="10dp"
            android:background="@drawable/currency13" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="@string/total"
            android:id="@+id/textView27"
            android:layout_marginStart="10dp"
            android:layout_gravity="center_vertical" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:id="@+id/textView28"
            android:layout_gravity="center_vertical"
            android:layout_marginStart="190dp" />

    </LinearLayout>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="08dp"
            android:id="@+id/imageView27"
            android:background="@drawable/line2"
            android:layout_marginTop="05dp" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:background="@android:color/white"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp">

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:id="@+id/imageView28"
                android:layout_marginStart="10dp"
                android:background="@drawable/credit101" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/paywith"
                android:id="@+id/textView29"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="10dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:id="@+id/textView30"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="180dp" />
        </LinearLayout>

    </LinearLayout>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView29"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:background="@drawable/ic_chevron_right_black_48dp" />


</LinearLayout>


请帮助…

为什么要使用以下代码行,请删除它们并检查效果:-

android:clickable="true"
next.setClickable(true);
虽然没有意识到它能起作用,但它在大多数情况下都能起作用


如果将视图设置为可单击,则它将使用单击,而不会将其传播到容器。

是否使用正确的id初始化了“下一步”按钮?下一步=(ImageView)findViewById(R.id.ImageView\u next);是的…@vasilisI运行您的代码并单击ImageView…@sid将日志消息放入
next.setOnClickListener(
并检查它是否正在调用。或者将任何土司放入
next.setOnClickListener中(
。我已将其从片段更改为活动。。感谢您的努力。@Syed Qasim AhmedI检查了一些与堆栈溢出相关的问题,有人建议这样做。。所以我已经尝试过。@Androider即使从所有位置删除,您也没有解决问题,因为它在这里毫无用处,请尝试下一步。setFocusable(true);此外,还可以尝试使用其他视图,如imagebutton,用于与可单击的内容一起单击
android:clickable="true"
next.setClickable(true);