캔버스에 이미지를 표시하기위한 것과 캔버스의 요소에 영향을주는 버튼이있는 두 개의 단편을 사용하는 활동에 착수했습니다. 두 개의 버튼에 대해 onClickListeners를 설정 했으므로 이제 프로그램이 충돌하지 않습니다. 이것은 실행될 때 즉시 발생하므로 logcat이이 부분과 완전히 관련이 있다고 말하면서 문제가 정확히 무엇인지 모릅니다. 나는 setOnClickListener를 잘못 구현한다고 가정 할 수 있습니다. 아무도 제가 잘못하고있는 것을 보도록 도와 줄 수 있습니까?안드로이드 - 파편에 setOnClickListener 크래킹
ToolbarFragment
package com.example.chris.drawingtest;
import android.app.Activity;
import android.app.Fragment;
import android.content.DialogInterface;
import android.nfc.Tag;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import com.example.chris.drawingtest.R;
/**
* Created by Chris on 11/28/2014.
*/
public class ToolbarFragment extends Fragment {
ToolSelectionListener mCallback;
ImageButton pencilButton, eraserButton;
public interface ToolSelectionListener {
public void sendNewValue(int newValue);
}
public void clicked(ImageButton imageButton) {
Log.d("we're listening...", "to the buttons!");
if (imageButton.getId() == eraserButton.getId())
mCallback.sendNewValue(1);
else
mCallback.sendNewValue(0);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
pencilButton = (ImageButton) getActivity().findViewById(R.id.pencil);
eraserButton = (ImageButton) getActivity().findViewById(R.id.eraser);
pencilButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
clicked(pencilButton);
}
});
eraserButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
clicked(eraserButton);
}
});
Log.d("Toolbar Inflation", "Inflating ToolbarFragment...");
return inflater.inflate(R.layout.fragment_toolbar, container, false);
}
}
** 편집 : ** 여기뿐만 아니라 일치하는 XML 파일입니다.
fragment_toolbar : 당신이 줄 수있는 모든 도움을
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="bottom|left"
android:orientation="horizontal"
>
<ImageButton
android:id="@+id/pencil"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="left"
android:background="@drawable/pencil"
/>
<ImageButton
android:id="@+id/eraser"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:background="@drawable/eraser"
/>
</LinearLayout>
감사합니다!
어디'R.id.pencil'와'R.id.eraser'이 선언되고? – Blackbelt
그들은 XML 파일에 있습니다.이 파일은 본문 본문에 추가했습니다. – user2828965