I'm trying to draw a circle in the middle of an ImageView. Below is my UI code.
<?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"
android:background="#android:color/white">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:id="#+id/bluh">
<ImageView
android:id="#+id/image_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:layout_weight="2"
android:src="#drawable/hhh" />
</LinearLayout>
<LinearLayout
android:id="#+id/l22Parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bluh"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/step18button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="39dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/step18textView"
android:layout_marginLeft="3dp"
android:layout_weight="1"
android:text="1"
android:textSize="13dp" />
<Button
android:id="#+id/step18button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="39dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/step18button1"
android:layout_marginLeft="3dp"
android:layout_toEndOf="#+id/step18button1"
android:layout_toRightOf="#+id/step18button1"
android:layout_weight="1"
android:text="2"
android:textSize="13dp" />
<Button
android:id="#+id/step18button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="39dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/step18button2"
android:layout_marginLeft="3dp"
android:layout_toEndOf="#+id/step18button2"
android:layout_toRightOf="#+id/step18button2"
android:layout_weight="1"
android:text="3"
android:textSize="13dp" />
<Button
android:id="#+id/step18button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="39dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/step18button3"
android:layout_marginLeft="3dp"
android:layout_toEndOf="#+id/step18button3"
android:layout_toRightOf="#+id/step18button3"
android:layout_weight="1"
android:text="4"
android:textSize="13dp" />
<Button
android:id="#+id/step18button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="39dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/step18button4"
android:layout_marginLeft="3dp"
android:layout_toEndOf="#+id/step18button4"
android:layout_toRightOf="#+id/step18button4"
android:layout_weight="1"
android:text="5"
android:textSize="13dp" />
<Button
android:id="#+id/step18button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="39dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/step18button5"
android:layout_marginLeft="3dp"
android:layout_toEndOf="#+id/step18button5"
android:layout_toRightOf="#+id/step18button5"
android:layout_weight="1"
android:text="6"
android:textSize="13dp" />
<Button
android:id="#+id/step18button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="39dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/step18button6"
android:layout_marginLeft="3dp"
android:layout_toEndOf="#+id/step18button6"
android:layout_toRightOf="#+id/step18button6"
android:layout_weight="1"
android:text="7"
android:textSize="13dp" />
<Button
android:id="#+id/step18button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="39dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/step18button7"
android:layout_marginLeft="3dp"
android:layout_toEndOf="#+id/step18button7"
android:layout_toRightOf="#+id/step18button7"
android:layout_weight="1"
android:text="8"
android:textSize="13dp" />
<Button
android:id="#+id/step18button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="39dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/step18button8"
android:layout_marginLeft="3dp"
android:layout_toEndOf="#+id/step18button8"
android:layout_toRightOf="#+id/step18button8"
android:layout_weight="1"
android:text="9"
android:textSize="13dp" />
</LinearLayout>
</LinearLayout>
The generated UI is below
Below is my Fragment class
/**
* Created by user on 5/12/2016.
*/
public class GeneralizationFragment extends Fragment {
Context context;
private ImageView imageView;
private int width;
private int height;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.generalization_fragment, container, false);
createBitMap(v);
return v;
}
public static GeneralizationFragment newInstance() {
GeneralizationFragment f = new GeneralizationFragment();
Bundle b = new Bundle();
f.setArguments(b);
return f;
}
#Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if(isVisibleToUser) {
Activity a = getActivity();
if(a != null) a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
private void createBitMap(final View v) {
BitmapFactory.Options myOptions = new BitmapFactory.Options();
myOptions.inDither = true;
myOptions.inScaled = true;
myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
myOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.hhh, myOptions);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLUE);
Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
imageView = (ImageView)v.findViewById(R.id.image_background);
ViewTreeObserver vto = imageView.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
imageView.getViewTreeObserver().removeOnPreDrawListener(this);
height = imageView.getMeasuredHeight();
width = imageView.getMeasuredWidth();
Log.d("GENERALIZED", "Width:" + width);
return true;
}
});
float radius = (float) (width-(width*0.2));
DisplayMetrics displaymetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
Canvas canvas = new Canvas(mutableBitmap);
canvas.drawCircle(100, 100, 60, paint);
imageView.setAdjustViewBounds(true);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageBitmap(mutableBitmap);
}
}
However I am not able to draw the circle (or the circle is not visible) until I remove imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); from my code. However that part is mandetory for me.
Also I have no idea of drawing it in the center.
Related
Hello i am making an app where i'm trying to make a cardview with imageview with rounded corner however when i run the app the rounded corners are not showing i dont know what exactly the problem is.
I tried using a custom imageview as well but when i sue that custom imageview imageis getting corner radius but black corners are showing on card and tried checking it on every api level like from android 5-8.
Please check my xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/primary_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="19dp"
android:layout_marginRight="19dp"
android:layout_marginTop="15dp"
app:cardCornerRadius="35dp"
app:contentPadding="0dp"
app:cardPreventCornerOverlap="false"
>
<ImageView
android:id="#+id/background_image_layout"
android:layout_width="match_parent"
android:layout_height="210dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/club1" />
<LinearLayout
android:id="#+id/background_image"
android:layout_width="match_parent"
android:layout_height="210dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_image"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:src="#drawable/ellipse" />
<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="horizontal"
android:padding="5dp">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="John Doe"
android:textColor="#color/White"
android:textSize="15sp"
/>
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/second_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="checked in to"
android:textColor="#color/White"
android:textSize="10sp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/third_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="W south"
android:textColor="#color/White"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="horizontal">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/fourth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="9dp"
android:text="beach mumbai"
android:textColor="#color/White"
android:textSize="15sp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/fifth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/second_text"
android:layout_toRightOf="#+id/fourth_text"
android:text="30 mins ago."
android:textColor="#color/White"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="85dp">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/sixth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:padding="10dp"
android:text="reply to abc............"
android:textColor="#color/White" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/favourite_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/ic_favorite_border_black_24dp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/seventh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:text="40 likes"
android:textColor="#color/White" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
My code for custom imageview
public class RoundedImageView extends ImageView {
private Path mMaskPath;
private Paint mMaskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private int mCornerRadius = 10;
public RoundedImageView(Context context) {
super(context);
init(context);
}
public RoundedImageView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
init(context);
}
public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
mMaskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
//mMaskPaint.setColor(context.getResources().getColor(R.color.transparent));
mCornerRadius = (int) context.getResources().getDimension(R.dimen.image_border_curvature);
}
/**
* Set the corner radius to use for the RoundedRectangle.
*/
public void setCornerRadius(int cornerRadius) {
mCornerRadius = cornerRadius;
generateMaskPath(getWidth(), getHeight());
invalidate();
}
#Override
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
super.onSizeChanged(w, h, oldW, oldH);
if (w != oldW || h != oldH) {
generateMaskPath(w, h);
}
}
private void generateMaskPath(int w, int h) {
mMaskPath = new Path();
mMaskPath.addRoundRect(new RectF(0,0,w,h), mCornerRadius, mCornerRadius, Path.Direction.CW);
mMaskPath.setFillType(Path.FillType.INVERSE_WINDING);
}
#SuppressLint("WrongConstant")
#Override
protected void onDraw(Canvas canvas) {
if(canvas.isOpaque()) { // If canvas is opaque, make it transparent
canvas.saveLayerAlpha(0, 0, canvas.getWidth(), canvas.getHeight(), 255, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
}
super.onDraw(canvas);
if(mMaskPath != null) {
canvas.drawPath(mMaskPath, mMaskPaint);
}
}
}
See this -
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/reviewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="19dp"
android:layout_marginRight="19dp"
android:layout_marginTop="15dp"
app:cardCornerRadius="35dp"
app:contentPadding="0dp"
app:cardPreventCornerOverlap="false">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imgProfile"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center"
android:layout_marginRight="100dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:src="#drawable/profile" />
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
I have 2 views for an item ListView. So one is used as HeaderView for ListView and the other in the other. That is the second marking takes the data from the DetailsAdapter, which respectively are initialized fields.
public class DetailsAdapter extends ArrayAdapter<TicketObjects> {
private int resource;
private LayoutInflater inflater;
private Context context;
public DetailsAdapter ( Context ctx, int resourceId, List<TicketObjects> objects) {
super( ctx, resourceId, objects );
resource = resourceId;
inflater = LayoutInflater.from( ctx );
context=ctx;
}
#Override
public View getView ( int position, View convertView, ViewGroup parent ) {
convertView = (LinearLayout) inflater.inflate( resource, null );
TicketObjects ticketObjects = getItem( position );
TextView depTransferCity = (TextView) convertView.findViewById(R.id.tvTransferCity);
TextView detDepartTime = (TextView) convertView.findViewById(R.id.detDepartTime);
TextView detDepartDate = (TextView) convertView.findViewById(R.id.detDepartDate);
TextView detArriveTime = (TextView) convertView.findViewById(R.id.detArriveTime);
TextView detArriveDate = (TextView) convertView.findViewById(R.id.detArriveDate);
TextView depDepartCity = (TextView) convertView.findViewById(R.id.depDepartCity);
TextView detDepartAirport = (TextView) convertView.findViewById(R.id.detDepartAirport);
TextView detArriveCity = (TextView) convertView.findViewById(R.id.detArriveCity);
TextView detArriveAirport = (TextView) convertView.findViewById(R.id.detArriveAirport);
TextView detFlight = (TextView) convertView.findViewById(R.id.detFlight);
ImageView airlineLogo = (ImageView) convertView.findViewById(R.id.detAirportLogo);
depTransferCity.setText(ticketObjects.getTransferCity());
detDepartTime.setText(ticketObjects.getDepartTime());
detDepartDate.setText(ticketObjects.getDepartDate());
detArriveTime.setText(ticketObjects.getArriveTime());
detArriveDate.setText(ticketObjects.getArriveDate());
depDepartCity.setText(ticketObjects.getDepartCity());
detDepartAirport.setText(ticketObjects.getDepartAirport());
detArriveCity.setText(ticketObjects.getArriveCity());
detArriveAirport.setText(ticketObjects.getArriveAirport());
detFlight.setText(ticketObjects.getFlight());
airlineLogo.setImageResource(ticketObjects.getAirlineLogo());
return convertView;
}
}
MainActivity:
public class MainActivity extends Activity {
private ListView lvDetails;
private Context ctx;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ticket_details);
ctx=this;
List<TicketObjects> ticketObjectses = new ArrayList<>();
ticketObjectses.add(new TicketObjects("Бишкек", "Манас", "Ош", "Аэропорт Оша", "FRU", "13:45", "16.09.2015", "OSS", "13:45", "16.09.2015", "Almaty", "1ч 15мин", "15000", R.drawable.logo_flyduba, "Рейс: 543"));
ticketObjectses.add(new TicketObjects("Ош", "Аэропорт Оша", "Новосибирск", "Толмачево", "OSS", "15:43", "16.09.2015", "OVB", "17:45", "16.09.2015", "Astana", "1ч 25мин", "16000", R.drawable.logo_kazak, "Рейс: 543"));
ticketObjectses.add(new TicketObjects("Алматы", "Алматы", "Москва", "Домодедово","ALA","11:54","16.09.2015","DME","12:44","16.09.2015","Novosibirsk", "2ч 15мин","13000", R.drawable.logo_pegasus_logo, "Рейс: 543"));
lvDetails = ( ListView ) findViewById( R.id.lvDetails);
ViewGroup header = (ViewGroup) getLayoutInflater().inflate(R.layout.ticket_details_header_item,lvDetails,false);
lvDetails.addHeaderView(header);
lvDetails.setAdapter(new DetailsAdapter(ctx, R.layout.ticket_details_item, ticketObjectses));
}
}
ticket_details_item_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/leftPadding"
android:layout_below="#+id/line"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout"
android:background="#drawable/layouts_border">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/iconsSize"
android:layout_gravity="center_horizontal"
android:padding="#dimen/leftPadding"
android:background="#e8e8e8"
android:layout_marginBottom="#dimen/rightPadding">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Бишкек"
android:id="#+id/detTitleArriveCity"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/imageView"
android:layout_toStartOf="#+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Нью-Йорк"
android:id="#+id/detTitleArriveCity"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageView"
android:layout_toEndOf="#+id/imageView" />
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/icon_depart"
android:padding="#dimen/rightPadding"
android:layout_marginLeft="#dimen/rightPadding"
android:layout_marginRight="#dimen/rightPadding" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="35ч 00м"
android:id="#+id/detTotalDuration"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainSmallSize"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/leftPadding"
android:gravity="center_vertical"
android:paddingLeft="#dimen/text_margin">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/rightPadding"
android:layout_weight="3"
android:gravity="center">
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView2"
android:src="#drawable/from"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView3"
android:src="#drawable/punktir"
android:layout_below="#+id/imageView2"
android:layout_marginTop="-5dp" />
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView4"
android:src="#drawable/to"
android:layout_below="#+id/imageView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="-5dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/rightPadding"
android:layout_weight="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="09:50"
android:id="#+id/detDepartTime"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12.06.2016"
android:id="#+id/detDepartDate"
android:layout_below="#+id/detDepartTime"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="#dimen/rightPadding"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11:40"
android:id="#+id/detArriveTime"
android:layout_below="#+id/detDepartDate"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="13.06.2016"
android:id="#+id/detArriveDate"
android:layout_below="#+id/detArriveTime"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/rightPadding"
android:layout_weight="2"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Бишкек"
android:id="#+id/depDepartCity"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Манас"
android:id="#+id/detDepartAirport"
android:layout_below="#+id/depDepartCity"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="#dimen/rightPadding"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Москва"
android:id="#+id/detArriveCity"
android:layout_below="#+id/detDepartAirport"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Шереметьево"
android:id="#+id/detArriveAirport"
android:layout_below="#+id/detArriveCity"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="#dimen/stndHeight"
android:layout_gravity="center_horizontal"
android:paddingTop="#dimen/leftPadding">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Рейс: AN565"
android:id="#+id/detFlight"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/detAirportLogo"
android:src="#drawable/logo_flyduba"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
ticket_details_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/leftPadding"
android:background="#e8e8e8"
android:gravity="center_vertical">
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/locIcon"
android:src="#drawable/location"
android:layout_weight="1"
android:padding="#dimen/leftPadding" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Пересадка:"
android:id="#+id/textviewTransfer"
android:layout_weight="3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvTransferCity"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize"
android:layout_weight="3" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/leftPadding"
android:gravity="center_vertical"
android:paddingLeft="#dimen/text_margin"
android:id="#+id/centerlayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/rightPadding"
android:layout_weight="3"
android:gravity="center">
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView2"
android:src="#drawable/from"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView3"
android:src="#drawable/punktir"
android:layout_below="#+id/imageView2"
android:layout_marginTop="-5dp" />
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView4"
android:src="#drawable/to"
android:layout_below="#+id/imageView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="-5dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/rightPadding"
android:layout_weight="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="09:50"
android:id="#+id/detDepartTime"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12.06.2016"
android:id="#+id/detDepartDate"
android:layout_below="#+id/detDepartTime"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="#dimen/rightPadding"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11:40"
android:id="#+id/detArriveTime"
android:layout_below="#+id/detDepartDate"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="13.06.2016"
android:id="#+id/detArriveDate"
android:layout_below="#+id/detArriveTime"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/rightPadding"
android:layout_weight="2"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Бишкек"
android:id="#+id/depDepartCity"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Манас"
android:id="#+id/detDepartAirport"
android:layout_below="#+id/depDepartCity"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="#dimen/rightPadding"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Москва"
android:id="#+id/detArriveCity"
android:layout_below="#+id/detDepartAirport"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Шереметьево"
android:id="#+id/detArriveAirport"
android:layout_below="#+id/detArriveCity"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="#dimen/stndHeight"
android:layout_gravity="center_horizontal"
android:paddingTop="#dimen/leftPadding">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Рейс: AN565"
android:id="#+id/detFlight"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/detAirportLogo"
android:src="#drawable/logo_flyduba"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
Now ticket_details_header_item.xml nothing displays, that is, there are no data. A second view As you can see in the adapter is initialized and it has data.
DetailObjects
package kz.ticketdetail;
import java.text.DecimalFormat;
public class TicketObjects {
private String departCity;
private String departAirport;
private String arriveCity;
private String arriveAirport;
private String departCode;
private String departTime;
private String departDate;
private String arriveCode;
private String arriveTime;
private String arriveDate;
private String transferCity;
private String flyDuration;
private String ticketPrice;
private int airlineLogo;
private String flight;
public TicketObjects(String departCity, String departAirport, String arriveCity, String arriveAirport,
String departCode, String departTime, String departDate,
String arriveCode, String arriveTime, String arriveDate,
String transferCity, String flyDuration, String ticketPrice, int airlineLogo, String flight) {
this.departCity = departCity;
this.departAirport = departAirport;
this.arriveCity = arriveCity;
this.arriveAirport = arriveAirport;
this.departCode = departCode;
this.departTime = departTime;
this.departDate = departDate;
this.arriveCode = arriveCode;
this.arriveTime = arriveTime;
this.arriveDate = arriveDate;
this.transferCity = transferCity;
this.flyDuration = flyDuration.trim().replaceFirst("^[0]{1}", "").replace(":", " h ") + " m";
this.ticketPrice = ticketPrice;
this.airlineLogo = airlineLogo;
this.flight = flight;
}
public static String getFormattingPrice(final String ticketPrice) throws IllegalArgumentException {
DecimalFormat formatter = new DecimalFormat("#,###,###");
return formatter.format(Float.parseFloat(ticketPrice)).replace(",", " ");
}
public String getDepartCity(){
return departCity;
}
public void setDepartCity(String departCity){
this.departCity = departCity;
}
public String getDepartAirport(){
return departAirport;
}
public void setDepartAirport(String departAirport){
this.departAirport = departAirport;
}
public String getArriveCity(){
return arriveCity;
}
public void setArriveCity(String arriveCity){
this.arriveCity = arriveCity;
}
public String getArriveAirport(){
return arriveAirport;
}
public void setArriveAirport(String arriveAirport){
this.arriveAirport = arriveAirport;
}
public String getFlight(){
return flight;
}
public void setFlight(String flight){
this.flight = flight;
}
public String getDepartCode(){
return departCode;
}
public void setDepartCode(String departCode){
this.departCode = departCode;
}
public String getDepartTime(){
return departTime;
}
public void setDepartTime(String departTime){
this.departTime = departTime;
}
public String getDepartDate(){
return departDate;
}
public void setDepartDate(String departDate){
this.departDate = departDate;
}
public String getArriveCode(){
return arriveCode;
}
public void setArriveCode(String arriveCode){
this.arriveCode = arriveCode;
}
public String getArriveTime(){
return arriveTime;
}
public void setArriveTime(String arriveTime){
this.arriveTime = arriveTime;
}
public String getArriveDate(){
return arriveDate;
}
public void setArriveDate(String arriveDate){
this.arriveDate = arriveDate;
}
public String getTransferCity(){
return transferCity;
}
public void setTransferCity(String transferCity){
this.transferCity = transferCity;
}
public String getFlyDuration(){
return flyDuration;
}
public void setFlyDuration(String flyDuration){
this.flyDuration = flyDuration;
}
public String getTicketPrice(){
return ticketPrice;
}
public void setTicketPrice(String ticketPrice){
this.ticketPrice = ticketPrice;
}
public int getAirlineLogo(){
return airlineLogo;
}
public void setAirlineLogo(int airlineLogo){
this.airlineLogo = airlineLogo;
}
}
Question: How header view display the data from the array which MainActivity? Where should occur initialization ticket_details_header_item?
You need to get the view from header and set data like this.
public class MainActivity extends Activity {
private ListView lvDetails;
private Context ctx;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ticket_details);
ctx=this;
List<TicketObjects> ticketObjectses = new ArrayList<>();
ticketObjectses.add(new TicketObjects("Бишкек", "Манас", "Ош", "Аэропорт Оша", "FRU", "13:45", "16.09.2015", "OSS", "13:45", "16.09.2015", "Almaty", "1ч 15мин", "15000", R.drawable.logo_flyduba, "Рейс: 543"));
ticketObjectses.add(new TicketObjects("Ош", "Аэропорт Оша", "Новосибирск", "Толмачево", "OSS", "15:43", "16.09.2015", "OVB", "17:45", "16.09.2015", "Astana", "1ч 25мин", "16000", R.drawable.logo_kazak, "Рейс: 543"));
ticketObjectses.add(new TicketObjects("Алматы", "Алматы", "Москва", "Домодедово","ALA","11:54","16.09.2015","DME","12:44","16.09.2015","Novosibirsk", "2ч 15мин","13000", R.drawable.logo_pegasus_logo, "Рейс: 543"));
lvDetails = ( ListView ) findViewById( R.id.lvDetails);
View header = getLayoutInflater().inflate(R.layout.ticket_details_header_item,lvDetails,false);
TextView text1 = (TextView) header.findViewById(R.id.detTitleArriveCity);
TextView text2 = (TextView) header.findViewById(R.id.detTotalDuration);
// do the same far all your text views or what ever you want to get from layout.
TicketObjects mTicketObjects = ticketObjectses.get(0);
text1.setText(mTicketObjects.getDepartCity());
text2.setText(mTicketObjects.getFlyDuration());
// do the same for other options.
lvDetails.addHeaderView(header);
lvDetails.setAdapter(new DetailsAdapter(ctx, R.layout.ticket_details_item, ticketObjectses));
}
}
do this for all items. inside the activity not in adapter. hope that answers your question.
I have developed a app. In my app there are:
Product.java (fragment)
product.xml (contain a listview and a include tag)
list_single(row of listview)
This is my code:
Product.java
public class Product extends Fragment{
public int ITEM_SELECTED = 1;
ArrayAdapter<String> PROD;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.product, container, false);
String [] ELEMENTS1 = {
"A","b","c"};
ListView listView = (ListView)v.findViewById(R.id.listView);
TextView a = (TextView)v.findViewById(R.id.textView);
ImageButton add_cart = (ImageButton)v.findViewById(R.id.button2);
switch(ITEM_SELECTED){
case 1: PROD = new ArrayAdapter<String>(getActivity(), R.layout.single_row, R.id.textView, ELEMENTS1);break;
}
listView.setAdapter(PROD);
add_cart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("asd","asd");
}
});
return v;
}
}
product.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:id="#+id/layout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="PRODOTTI"
android:id="#+id/textView10"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:textColor="#000"
android:textSize="20dp"
android:textStyle="bold"
android:typeface="monospace" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"
android:layout_marginTop="85dp"
android:id="#+id/view1"
android:layout_centerHorizontal="true"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_below="#+id/view1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp" />
<include layout="#layout/single_row"
android:id="#+id/ly"
android:visibility="gone"/>
</RelativeLayout>
and this is list_single.xml
<?xml version="1.0" encoding="utf-8"?>
<EditText
android:layout_width="40dp"
android:layout_height="wrap_content"
android:inputType="numberSigned"
android:ems="10"
android:id="#+id/editText"
android:layout_alignBottom="#+id/button2"
android:layout_toLeftOf="#+id/button2"
android:layout_toStartOf="#+id/button2" />
<ImageButton
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2"
android:src="#drawable/product"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#null"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Q.TA"
android:textColor="#083CBF"
android:id="#+id/textView2"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/editText"
android:layout_alignStart="#+id/editText"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PREZZO"
android:textColor="#083CBF"
android:id="#+id/textView3"
android:layout_alignTop="#+id/textView2"
android:layout_toLeftOf="#+id/textView2"
android:layout_toStartOf="#+id/textView2"
android:layout_marginRight="10dp" />
<EditText
android:layout_width="50dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText2"
android:layout_alignTop="#+id/editText"
android:layout_alignLeft="#+id/textView3"
android:layout_alignStart="#+id/textView3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="COLLI"
android:textColor="#083CBF"
android:id="#+id/textView4"
android:layout_alignTop="#+id/textView3"
android:layout_toLeftOf="#+id/textView3"
android:layout_toStartOf="#+id/textView3"
android:layout_marginRight="20dp" />
<EditText
android:layout_width="50dp"
android:layout_height="wrap_content"
android:inputType="numberSigned"
android:ems="10"
android:id="#+id/editText3"
android:layout_alignTop="#+id/editText2"
android:layout_alignLeft="#+id/textView4"
android:layout_alignStart="#+id/textView4" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/textView"
android:layout_toStartOf="#+id/textView4"
android:id="#+id/ded"
android:layout_toLeftOf="#+id/textView4"
android:layout_marginRight="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:singleLine="false"
android:id="#+id/textView"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center" />
</FrameLayout>
Problem:
When i try to click on imagebutton it doesn't show Log.d. It seems that
OnClickListener is not run. I have tried: setText("xy"); but that doesn't work either.
Is the problem is in listview?
I can't use the elements of single_row. My app doesn't crash. Please, help! Thank you
UPDATE:
listView.setAdapter(PROD);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
ImageButton add_cart = (ImageButton) view.findViewById(R.id.button2);
add_cart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("asd", "asd");
Toast.makeText(getActivity(), "hi",
Toast.LENGTH_LONG).show();
}
});
}
});
This doesn't work for me...
You are doing it wrong.
ImageButton add_cart = (ImageButton)v.findViewById(R.id.button2);
Your imagebutton button2 is in list_single.xml and you are trying to find it in View inflated using product.xml. And that too before you are setting the adapter for the ListView. So at the point where you are getting reference to your ImageButton there is view rendering for the ListView. Here is what you should ideally do
listView.setAdapter(PROD);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
ImageButton add_cart = (ImageButton)view.findViewById(R.id.button2);
//more logic
}
});
Here is the log,
this log shows as many times as the itemView's number.
but my app is still runing normally.
D/ViewGroup﹕ addInArray been called, this = android.support.v7.widget.RecyclerView{44dd4fc8 VFEDID 0,86-720,1140 7f0e01cc app:id/order_query_rv}call stack =
java.lang.Throwable: addInArray
at android.view.ViewGroup.addInArray(ViewGroup.java:3788)
at android.view.ViewGroup.addViewInner(ViewGroup.java:3742)
at android.view.ViewGroup.addView(ViewGroup.java:3566)
at android.view.ViewGroup.addView(ViewGroup.java:3511)
at android.support.v7.widget.RecyclerView$4.addView(RecyclerView.java:538)
at android.support.v7.widget.ChildHelper.addView(ChildHelper.java:83)
at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:6025)
at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:5983)
at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:5971)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1373)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1322)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:556)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2673)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:2971)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1160)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2323)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2029)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1192)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6231)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:817)
at android.view.Choreographer.doCallbacks(Choreographer.java:619)
at android.view.Choreographer.doFrame(Choreographer.java:588)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:803)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5409)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:859)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:675)
at dalvik.system.NativeStart.main(Native Method)
I search for a long time ,and i still can't find a way to solve it 。
what cause this Throwable,how to solve it.
Activity
public class OrderQueryActivity extends BaseActivity implements IOrderQueryView {
#Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.base_mains);
super.onCreate(savedInstanceState);
dealTopMenu();
this.iPresenter = new OrderQueryPresenter(OrderQueryActivity.this, new OrderQueryDao());
}
#Override
public void initView() {
super.initView();
final View contentView = View.inflate(getContext(), R.layout.layout_online_order_query, null);
this.orderQueryTitle = (LinearLayout) contentView.findViewById(R.id.order_query_title_ll);
this.addView(contentView);
this.sumNum = (TextView) contentView.findViewById(R.id.order_num_tv);
this.sumWeigh = (TextView) contentView.findViewById(R.id.order_weight);
this.sumAmount = (TextView) contentView.findViewById(R.id.order_total_amount);
this.rv = (RecyclerView) contentView.findViewById(R.id.order_query_recycler_view);
this.rv.setHasFixedSize(true);
this.rv.setLayoutManager(new LinearLayoutManager(getContext()));
}
#Override
public void setAdapterForRv() {
this.adapter = new OrderQueryAdapter(iPresenter);
this.rv.setAdapter(adapter);
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/order_query_title_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/gray"
android:orientation="vertical"
android:visibility="invisible">
<TextView
style="#style/online_order_query_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:paddingTop="4dp"
android:text="#string/total_order_num" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="horizontal"
android:paddingLeft="72dp">
<TextView
android:id="#+id/order_num_tv"
style="#style/online_order_query_title_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/order_number_example" />
<TextView
style="#style/online_order_query_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/order_number_unit" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="#+id/order_weight"
style="#style/online_order_query_title_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/order_weight_example" />
<TextView
style="#style/online_order_query_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/weight_unit" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:id="#+id/order_total_amount"
style="#style/online_order_query_title_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/order_total_amount_example" />
<TextView
style="#style/online_order_query_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="4dp"
android:text="#string/money_unit" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/order_query_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</LinearLayout>
Adapter
public class OrderQueryAdapter extends RecyclerView.Adapter<OrderQueryAdapter.ViewHolder> {
private ArrayList<OrderBean> orderData;
private IOrderQueryPresenter presenter;
public OrderQueryAdapter(IOrderQueryPresenter presenter) {
this.presenter = presenter;
this.orderData = presenter.getOrderData();
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.query_online_order_card_item, parent, false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
OrderBean order = orderData.get(position);
holder.dealerName.setText(order.getChannelName());
holder.orderTime.setText(order.getOrderTime());
holder.orderStatus.setText(order.getOrderStatus());
holder.prodsNum.setText(order.getOrderSumNumber());
holder.prodsWeight.setText(order.getWeight());
holder.orderAmount.setText(order.getOrderSumPrice());
holder.payment.setText(order.getPayAmount());
OnDetailClickListener onDetailClickListener = new OnDetailClickListener(presenter, position);
holder.orderContentll.setOnClickListener(onDetailClickListener);
}
#Override
public int getItemCount() {
return orderData.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
TextView dealerName, orderTime, orderStatus, prodsNum, prodsWeight, orderAmount, payment;
LinearLayout orderContentll;
public ViewHolder(View view) {
super(view);
this.dealerName = (TextView) view.findViewById(R.id.dealer_name);
this.orderTime = (TextView) view.findViewById(R.id.order_time);
this.orderStatus = (TextView) view.findViewById(R.id.order_status);
this.prodsNum = (TextView) view.findViewById(R.id.prod_count_online_order);
this.prodsWeight = (TextView) view.findViewById(R.id.prod_weight_online_order);
this.orderAmount = (TextView) view.findViewById(R.id.prod_amount_online_order);
this.payment = (TextView) view.findViewById(R.id.payment_order_online);
this.orderContentll = (LinearLayout) view.findViewById(R.id.ll_order_content);
}
}
static class OnDetailClickListener implements View.OnClickListener {
private int position;
private IOrderQueryPresenter presenter;
public OnDetailClickListener(IOrderQueryPresenter presenter, int position) {
this.presenter = presenter;
this.position = position;
}
#Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.ll_order_content:
presenter.startOrderDetail(position);
break;
}
}
}
}
item xml
<?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="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="2dp">
<android.support.v7.widget.CardView
android:id="#+id/online_pay_card_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="8dp">
<LinearLayout
android:id="#+id/ll_dealer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:orientation="horizontal">
<TextView
android:id="#+id/dealer_name"
style="#style/online_order_query_primary_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dealer_name" />
<TextView
android:id="#+id/order_time"
style="#style/online_order_query_primary_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:text="#string/order_time_example" />
</LinearLayout>
<ImageView
android:id="#+id/divider_one"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/ll_dealer"
android:background="#drawable/single_divider_line_black"
android:contentDescription="#string/app_name" />
<LinearLayout
android:id="#+id/ll_order_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/divider_one"
android:background="#drawable/order_detail_selector"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:orientation="horizontal">
<TextView
style="#style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/order_status_str" />
<TextView
android:id="#+id/order_status"
style="#style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:text="#string/order_status_example" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left"
android:orientation="horizontal">
<TextView
style="#style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/prod_num_str" />
<TextView
android:id="#+id/prod_count_online_order"
style="#style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:text="#string/prod_num_example" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
style="#style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/prod_weight" />
<TextView
android:id="#+id/prod_weight_online_order"
style="#style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:text="#string/weight_example" />
<TextView
style="#style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/weight_unit" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left"
android:orientation="horizontal">
<TextView
style="#style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/order_amount" />
<TextView
android:id="#+id/prod_amount_online_order"
style="#style/online_order_query_primary_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="4dp"
android:text="#string/order_amount_example" />
<TextView
style="#style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/money_unit" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/divider_two"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/ll_order_content"
android:background="#drawable/single_divider_line_black"
android:contentDescription="#string/app_name" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/divider_two"
android:layout_margin="4dp"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:gravity="left"
android:orientation="horizontal">
<TextView
style="#style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/already_payment" />
<TextView
android:id="#+id/payment_order_online"
style="#style/online_order_query_primary_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:text="#string/order_payment_example" />
<TextView
style="#style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/money_unit" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:orientation="horizontal">
<Button
android:id="#+id/payment_detail_btn"
style="#style/iBtn_listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mm_title_btn_right"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:text="#string/payment_detail" />
<Button
android:id="#+id/pay_online_order_btn"
style="#style/iBtn_listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:background="#drawable/mm_title_btn_right"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:text="#string/pay_online_order" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
I had the same problem ...
the problem disappeared after changing my code in fragment
from
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
...
detailAdapter = new TitleAdapter(getChildFragmentManager(),getActivity());//remove this
...
}
on
#Override
public void onAttach(Context context) {
super.onAttach(context);
detailAdapter = new TitleAdapter(getActivity().getSupportFragmentManager (),getActivity());//add this
}
I have three fragments, Player1Tun, Player2Turn and TicTacToeLayout. Player1Turn and Player2Turn are inner-switching every time a player makes a move and TicTacToeLayout contains the tic tac toe table which update everytime the fragments switches. What I'm trying to do is to send the data from either player fragments to the host activity (while the program is still running) and then from there, I'll update the table in the TicTacToeLayout. Any ideas or method I can do it?
Player1:
package As2.packageTK;
//import android.app.Activity;
import java.util.ArrayList;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.app.Activity;
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.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class PlayerTurn2 extends Fragment{
TextView p2Name;
TextView p2Icon;
Button doneP2;
Button resetP2;
EditText row;
EditText column;
TicTacToeLayout myObject2 = new TicTacToeLayout();
ArrayList<String> player2;
Bundle extras = new Bundle();
int turn = 2;
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.playerturn2, container, false);
return view;
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
extras = getArguments();
player2 = new ArrayList<String>(extras.getStringArrayList("player2"));
//Toast.makeText(getActivity(), player2.get(0), Toast.LENGTH_LONG).show();
//Toast.makeText(getActivity(), player2.get(1), Toast.LENGTH_LONG).show();
p2Name = (TextView) getActivity().findViewById(R.id.p2NameInfo);
p2Icon = (TextView) getActivity().findViewById(R.id.p2IconInfo);
row = (EditText) getActivity().findViewById(R.id.rowP2);
column = (EditText) getActivity().findViewById(R.id.columnP2);
doneP2 = (Button) getActivity().findViewById(R.id.doneP2);
//resetP2 = (Button) getActivity().findViewById(R.id.resetP2);
setPlayer(); //sets all the information of player 2, name, icon, image, etc
doneP2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
callPlayer1Fragment(); //switches with first player
}
});
}
public void callPlayer1Fragment()
{
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment Player1Frag = new PlayerTurn1();
Player1Frag.setArguments(extras);
ft.replace(R.id.fragment_container, Player1Frag);
ft.commit();
}
public boolean checkField()
{
if(row == null || column == null)
{
Toast.makeText(getActivity(), "Please input the row or column!", Toast.LENGTH_LONG).show();
return false;
}
else
return true;
}
public void setPlayer()
{
String name = player2.get(0);
if(!name.equals(""))
p2Name.setText("Player Name: " + name);
else
p2Name.setText("");
String icon = player2.get(1);
if(!icon.equals(""))
p2Icon.setText("Player Icon: " + icon);
else
p2Icon.setText("");
}
}
player 2 fragment is exactly the same code so I won't bother adding it.
TicTacToeLayout fragment class:
public class TicTacToeLayout extends Fragment {
TextView image1, image2, image3, image4, image5, image6, image7, image8, image9;
TextView[][] images;
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.tictactoe_layout, container, false);
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
image1 = (TextView) getActivity().findViewById(R.id.Image1);
image2 = (TextView) getActivity().findViewById(R.id.Image2);
image3 = (TextView) getActivity().findViewById(R.id.Image3);
image4 = (TextView) getActivity().findViewById(R.id.Image4);
image5 = (TextView) getActivity().findViewById(R.id.Image5);
image6 = (TextView) getActivity().findViewById(R.id.Image6);
image7 = (TextView) getActivity().findViewById(R.id.Image7);
image8 = (TextView) getActivity().findViewById(R.id.Image8);
image9 = (TextView) getActivity().findViewById(R.id.Image9);
images = new TextView[][]{ {image1, image2, image3},
{image4, image5, image6},
{image7, image8, image9} };
toast();
}
public void toast()
{
Toast.makeText(getActivity(), images[0][0].getText().toString(), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), images[0][1].getText().toString(), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), images[0][2].getText().toString(), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), images[1][0].getText().toString(), Toast.LENGTH_LONG).show();
}
public void play(int row, int column, String icon)
{
images[row-1][column-1].setText(icon);
}
}
here's the XML layout for playerturn2
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="#+id/tablerow0"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/player2Num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginLeft="100dp"
android:gravity="center_horizontal"
android:text="Player 2"
android:textSize="20dp" />
</TableRow>
<TableRow
android:id="#+id/tablerow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/p2NameInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player Name: "
android:textSize="20dp" />
</TableRow>
<TableRow
android:id="#+id/tablerow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/p2IconInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player icon: "
android:textSize="20dp" />
</TableRow>
<TableRow
android:id="#+id/tablerow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/p2PicInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player picture:"
android:textSize="20dp" />
</TableRow>
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#android:drawable/editbox_background" />
<TableRow
android:id="#+id/rowNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginLeft="50dp"
android:gravity="center_horizontal"
android:text="Row (1-3):"
android:textSize="20dp" />
<EditText
android:id="#+id/rowP2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:width="50dp" />
</TableRow>
<TableRow
android:id="#+id/colNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginLeft="50dp"
android:gravity="center_horizontal"
android:text="Col (1-3):"
android:textSize="20dp" />
<EditText
android:id="#+id/columnP2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:width="50dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp" >
<Button
android:id="#+id/doneP2"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="Done"
/>
<Button
android:id="#+id/resetP2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
/>
</TableRow>
</TableLayout>
here's the layout for tictactoelayout.xml
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tictactoe"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" >
<TextView
android:id="#+id/Image1"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="1"
android:textSize="70dp" />
<TextView
android:id="#+id/Image2"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="2"
android:textSize="70dp" />
<TextView
android:id="#+id/Image3"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="3"
android:textSize="70dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/Image4"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="4"
android:textSize="70dp" />
<TextView
android:id="#+id/Image5"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="5"
android:textSize="70dp" />
<TextView
android:id="#+id/Image6"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="6"
android:textSize="70dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/Image7"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="7"
android:textSize="70dp" />
<TextView
android:id="#+id/Image8"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="8"
android:textSize="70dp" />
<TextView
android:id="#+id/Image9"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="9"
android:textSize="70dp" />
</TableRow>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:id="#+id/win"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Winner"
android:textSize="20dp" />
<EditText
android:id="#+id/winner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:ems="10" />
</RelativeLayout>
</TableLayout>
and finally the host activity's xml layout: tictactoegame.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/frag2"
android:name="As2.packageTK.TicTacToeLayout"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
My friend did the same but with a implementing an interface he created in the fragments and having the main activity implement the interface. With that, he used a method to pass datas. Maybe it's not clear but if you know what I'm trying to say then you could clear it out for all of us :)
your friend is right, communicating with other fragments is nicely explained in the docs:
http://developer.android.com/training/basics/fragments/communicating.html