I have a fragment class Frag2
and a view class Rectangle
which sends onDraw to another fragment class Frag1
, and i need to send some data to Rectangle
from Frag 2
.
what do i do ? :D
(sorry its abit messy ive been trying everything for last 24 hours.)
Frag 2
public class FragmentTwo extends Fragment {
TextView changingText;
Button changeTextButton;
Button XButton;
Button YButton;
private int SecondX;
NumberPicker Pick100 = null;
private int entered;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View myInflatedView = inflater.inflate(R.layout.fragment_two_layout, container, false);
changingText = (TextView) myInflatedView.findViewById(R.id.textView);
changeTextButton = (Button) myInflatedView.findViewById(R.id.button);
XButton = (Button) myInflatedView.findViewById(R.id.buttonX);
YButton = (Button) myInflatedView.findViewById(R.id.buttonY);
Pick100 = (NumberPicker) myInflatedView.findViewById(R.id.secondD);
changeTextViewValueRandomlyOnButtonClick();
return myInflatedView;
}
private void changeTextViewValueRandomlyOnButtonClick() {
final String[] text = {"A", "B", "C", "D"};
changeTextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Random rand = new Random();
int random = rand.nextInt(100) + 1;
if (random == 100) changingText.setText(text[3]);
if (random > 90 && random <= 99) changingText.setText(text[2]);
if (random < 60 && random >= 1) changingText.setText(text[0]);
if (random >= 60 && random <= 90) changingText.setText(text[1]);
}
});
}
You can ignore most of it really. Im trying to send Pick100 to this class
public class Rectangle extends View {
//FragmentTwo F2 = new FragmentTwo();
public Rectangle(Context context) {
super(context);
}
public Rectangle(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public Rectangle(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Log.d("X","RED DOT EUQALS TO "+x);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.RED);
canvas.drawRect(x,100,x+60,100+60,paint);
}
}
The Rectangle works fine.It sends a rect to Frag1 i just want to be able to send the number here and sub it in x ( int rectangle)
Frag 1 class :
public class FragmentOne extends Fragment {
RelativeLayout relativeLayout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View myInflatedView= inflater.inflate(R.layout.fragment_one_layout,container,false);
return myInflatedView;
}
}
Frag 1 xml :
<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/Frag1"
android:layout_height="match_parent"
android:background="#000">
<com.redot.puzzle1.Rectangle
android:id="@+id/Rect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>