here is the picture. i want to click signs & Symptoms from the table of contents and by clicking i want it to jumps directly to the Signs and Symptoms paragraph. Please solve my this problem. here is my code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".Atherosclerosis"
tools:ignore="UselessParent,ScrollViewCount" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/tablecontentlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#EFECCB" >
<TextView
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:textStyle="bold"
android:textColor="#000000"
android:text="#string/table" />
<TextView
android:id="#+id/definitionid"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="#string/Definition" />
<TextView
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="#string/RiskFactors" />
<TextView
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="#string/Pathophysiology" />
<TextView
android:id="#+id/Signandsymptompsid"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="#string/SignsandSymptoms" />
<TextView
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="#string/Diagnosis" />
<TextView
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="#string/Treatment" />
<TextView
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="#string/Prevention" />
<TextView
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="#string/Complications" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tablecontentlayout"
android:layout_marginTop="15dp"
android:orientation="vertical" >
<TextView
android:id="#+id/atherodefinition"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Definition"
android:background="#F5F5F5"
android:textColor="#264177"
android:textSize="17sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/atherosclerosisdefinition"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/RiskFactors"
android:background="#F5F5F5"
android:textColor="#264177"
android:textSize="17sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Modifiable"
android:textStyle="bold"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/modifiableatherosclerosis"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Nonmodifiable"
android:textStyle="bold"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/nonmodifiableatherosclerosis"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Pathophysiology"
android:background="#F5F5F5"
android:textColor="#264177"
android:textSize="17sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/pathophysiologyatherosclerosis"
android:textSize="15sp"/>
<TextView
android:id="#+id/Signandsymptomsparagraph"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/SignsandSymptoms"
android:background="#F5F5F5"
android:textColor="#264177"
android:textSize="17sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/atherosclerosissignsandsymptoms"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Diagnosis"
android:background="#F5F5F5"
android:textColor="#264177"
android:textSize="17sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Diagnosisatherosclerosis"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Treatment"
android:background="#F5F5F5"
android:textColor="#264177"
android:textSize="17sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/lifestylemodification"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/treatmentatherosclerosis"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Prevention"
android:background="#F5F5F5"
android:textColor="#264177"
android:textSize="17sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Preventionatherosclerosis"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Complications"
android:background="#F5F5F5"
android:textColor="#264177"
android:textSize="17sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/complicationatherosclerosis"
android:textSize="15sp"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
my java code for this layout:
public class Atherosclerosis extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.atherosclerosis);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.atherosclerosis, menu);
return true;
}
}
Use android:onClick="" and android:Clickable="true"
to make the Textview as a button
You can use OnClickListener on TextView and then use the following method on the OnClick, where textViewAbove is the TextView that is above the one you need to jump:
scrollView.post(
new Runnable() {
#Override
public void run() {
new CountDownTimer(1500, 20) {
#Override
public void onTick(long millisUntilFinished) {
scrollView.scrollTo(0, (int) (textViewAbove.getBottom()-millisUntilFinished));
}
#Override
public void onFinish() {
}
}.start();
}
}
);
Hope it helps!
You can have OnclickListener on TextView
Here is the code but still give me error till me where I am wrong?
public class Atherosclerosis extends Activity{
ScrollView scrollView;
TextView tvabove=(TextView)findViewById(R.id.pathophysiology_id);
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.atherosclerosis);
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#6B8E23")));
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
TextView tv=(TextView)findViewById(R.id.Signandsymptompsid);
tv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
scrollView.post(
new Runnable() {
#Override
public void run() {
new CountDownTimer(1500, 20) {
#Override
public void onTick(long millisUntilFinished) {
scrollView.scrollTo(0, (int) (tvabove.getBottom()-millisUntilFinished));
}
#Override
public void onFinish() {
}
}.start();
}
}
);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.atherosclerosis, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Take appropriate action for each action item click
switch (item.getItemId()) {
case R.id.id_search:
Intent newActivity0 = new Intent(this,Search.class);
startActivity(newActivity0);
return true;
case R.id.id_favorit:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Related
I am trying to get the position of items in my RecyclerView, mainly those that are at [0], [1], and [2] positions. The reason being is currently I am creating a leader board that will highlight the top 3 players with the highest score.
I have tried calling getAdapterPosition() but I guess I am using it incorrectly.
if(holder.getAdapterPosition() == 0)
{
Glide.with(holder.firstPlace.getContext())
.load(model.getUrl())
.into(holder.firstPlace);
}
I would greatly appreciate if someone could point me to the right direction. Thank you.
Edit 1:
My UserAdapter
public class UserAdapter extends FirestoreRecyclerAdapter<UserModel, UserAdapter.UserViewHolder> {
public UserAdapter(#NonNull FirestoreRecyclerOptions<UserModel> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull UserAdapter.UserViewHolder holder, int position, #NonNull UserModel model) {
holder.username.setText(model.getFullName());
holder.email.setText(model.getEmail());
holder.score.setText(model.getScore()+"");
holder.rank.setText(String.valueOf(position + 1));
Glide.with(holder.userImage.getContext())
.load(model.getUrl())
.into(holder.userImage);
//error here
// if(holder.getAdapterPosition() == 0)
// {
// Glide.with(holder.firstPlace.getContext())
// .load(model.getUrl())
// .into(holder.firstPlace);
// }
}
#NonNull
#Override
public UserAdapter.UserViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_leaderboard_single, parent, false);
return new UserViewHolder(view);
}
public class UserViewHolder extends RecyclerView.ViewHolder {
CircleImageView userImage;
TextView username;
TextView email;
TextView score;
TextView rank;
CircleImageView firstPlace;
CircleImageView secondPlace;
CircleImageView thirdPlace;
public UserViewHolder(#NonNull View itemView) {
super(itemView);
userImage = itemView.findViewById(R.id.list_image);
username = itemView.findViewById(R.id.list_username);
email = itemView.findViewById(R.id.list_email);
score = itemView.findViewById(R.id.list_score);
rank = itemView.findViewById(R.id.leaderboard_position);
firstPlace = itemView.findViewById(R.id.place1stProfile);
secondPlace = itemView.findViewById(R.id.place2ndProfile);
thirdPlace = itemView.findViewById(R.id.place3rdProfile);
}
}
list_leaderboard_single.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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:background="#EFCDB4">
<RelativeLayout
android:layout_width="32dp"
android:layout_height="match_parent"
android:padding="5dp"
android:background="#FFE5C6"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/leaderboard_position"
android:textStyle="bold"
android:textColor="#000"
android:text="##"
android:layout_centerInParent="true"
android:textSize="18sp"
/>
</RelativeLayout>
<de.hdodenhof.circleimageview.CircleImageView
android:paddingTop="5dp"
android:layout_width="75dp"
android:layout_height="75dp"
android:id="#+id/list_image"
android:src="#mipmap/ic_launcher_round"
android:scaleType="centerCrop"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#id/leaderboard_position"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/list_username"
android:layout_width="173dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_marginTop="26dp"
android:fontFamily="#font/poppinsmedium"
android:layout_toRightOf="#id/list_image"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Username"
android:textColor="#000"
android:textSize="18sp" />
<TextView
android:id="#+id/list_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:layout_toRightOf="#+id/list_username"
android:layout_centerVertical="true"
android:layout_marginLeft="0dp"
android:textColor="#000"
android:visibility="gone"
/>
</LinearLayout>
<LinearLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_marginTop="0dp"
android:id="#+id/list_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Score"
android:textSize="25sp"
android:textColor="#000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PTS"
android:textStyle="bold"
android:fontFamily="#font/poppinsbold"
android:textSize="15sp"
android:textColor="#000"/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
app:srcCompat="#drawable/ic_blood_drop"
android:visibility="gone"
/>
</LinearLayout>
fragment_leaderboard.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
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:layout_height="match_parent"
tools:context=".Leaderboard"
android:background="#790604">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="15dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="L E A D E R B O A R D"
android:fontFamily="#font/poppinsbold"
android:textColor="#ffffff"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
android:layout_marginBottom="16dp"
android:minHeight="150dp">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/place2ndProfile"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="16dp"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true"
android:src="#mipmap/ic_launcher_round"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:layout_below="#id/place2ndProfile"
android:fontFamily="#font/poppinsbold"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:textColor="#ffffff"
android:text="2ND"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/place1stProfile"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_marginTop="16dp"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true"
android:src="#mipmap/ic_launcher_round"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#ffffff"
android:fontFamily="#font/poppinsbold"
android:layout_below="#id/place1stProfile"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:text="1ST"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/place3rdProfile"
android:src="#mipmap/ic_launcher_round"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="16dp"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:fontFamily="#font/poppinsbold"
android:layout_below="#id/place3rdProfile"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:text="3RD"/>
</RelativeLayout>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/leaderboard_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
You should call holder.getAdapterPosition only within the ViewHolder; instead you can simply use the parameter position passed in onBindViewHolder().
#Override
protected void onBindViewHolder(#NonNull UserAdapter.UserViewHolder holder, int position, #NonNull UserModel model) {
// .....
if(position == 0)
{
Glide.with(holder.firstPlace.getContext())
.load(model.getUrl())
.into(holder.firstPlace);
}
I made the shopping cart app and I use the navigation drawer and in this navigation drawer I use the shopping cart icon.
Now, When i click on the particular item. It's open in new activity but its not showing the shopping cart icon, So how will it show? So,i see the item in the cart?
ItemDetailsActivity. java (This is the .java file of this image where i am unable to see the shopping cart icon, so i am unable to see how many items add in the cart)
public class ItemDetailsActivity extends AppCompatActivity {
int imagePosition;
String stringImageUri;
TextView textViewshare, textViewmap;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_details);
SimpleDraweeView mImageView = (SimpleDraweeView)findViewById(R.id.image1);
TextView textViewAddToCart = (TextView)findViewById(R.id.text_action_bottom1);
TextView textViewBuyNow = (TextView)findViewById(R.id.text_action_bottom2);
textViewshare = (TextView) findViewById(R.id.text_action1);
textViewmap = (TextView) findViewById(R.id.text_action3);
TextView textViewBuyNowwithpayment = (TextView) findViewById(R.id.text_action_bottom2);
//Getting image uri from previous screen
if (getIntent() != null) {
stringImageUri = getIntent().getStringExtra(ImageListFragment.STRING_IMAGE_URI);
imagePosition = getIntent().getIntExtra(ImageListFragment.STRING_IMAGE_URI,0);
}
Uri uri = Uri.parse(stringImageUri);
mImageView.setImageURI(uri);
mImageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(ItemDetailsActivity.this, ViewPagerActivity.class);
intent.putExtra("position", imagePosition);
startActivity(intent);
}
});
textViewAddToCart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ImageUrlUtils imageUrlUtils = new ImageUrlUtils();
imageUrlUtils.addCartListImageUri(stringImageUri);
Toast.makeText(ItemDetailsActivity.this,"Item added to cart.",Toast.LENGTH_SHORT).show();
MainActivity.notificationCountCart++;
NotificationCountSetClass.setNotifyCount(MainActivity.notificationCountCart);
}
});
textViewBuyNow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ImageUrlUtils imageUrlUtils = new ImageUrlUtils();
imageUrlUtils.addCartListImageUri(stringImageUri);
MainActivity.notificationCountCart++;
NotificationCountSetClass.setNotifyCount(MainActivity.notificationCountCart);
startActivity(new Intent(ItemDetailsActivity.this, CartListActivity.class));
}
});
// payment.setOnClickListener(new View.OnClickListener() {
// #Override
// public void onClick(View v) {
// Intent i = new Intent(ItemDetailsActivity.this, PayPalCheckoutActivity.class);
// startActivity(i);
// }
// });
textViewBuyNowwithpayment.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(ItemDetailsActivity.this, PayPalCheckoutActivity.class);
startActivity(i);
}
});
textViewshare.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "SUBJECT");
intent.putExtra(Intent.EXTRA_TEXT,"Extra Text");
startActivity(intent);
}
});
textViewmap.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent in = new Intent(ItemDetailsActivity.this, Placepicker.class);
startActivity(in);
}
});
}
}
activity_item_details.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/activity_item_details"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10"
tools:context="com.codeexpertise.eshop.product.ItemDetailsActivity">
<ScrollView android:id="#+id/scrollbar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9.5"
android:scrollbars="none"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.facebook.drawee.view.SimpleDraweeView xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:id="#+id/image1"
android:layout_width="match_parent"
android:layout_height="200.0dp"
fresco:placeholderImage="#color/stay_color" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:orientation="vertical">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Denim Shirt"
android:textSize="16dp"
android:textColor="#color/gen_black"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Rs. 1,979"
android:textSize="20dp"
android:textColor="#color/gen_black"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FREE Delivery"
android:textSize="12dp"
android:layout_marginTop="4dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="8dp">
<TextView android:id="#+id/text_ratings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/green_light"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:text="4.3 *"
android:textSize="12dp"
android:textColor="#color/gen_white"
android:textStyle="bold"/>
<TextView android:id="#+id/text_ratings_reviews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:text="50 ratings \u0026 15 reviews"
android:textSize="12dp"/>
</LinearLayout>/
<View android:layout_width="match_parent"
android:layout_height="#dimen/view_width_small"
android:background="#color/grey_light"
android:layout_marginTop="8dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:layout_marginTop="8dp"
android:weightSum="3">
<LinearLayout android:id="#+id/layout_action1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_share_black_18dp"/>
<TextView android:id="#+id/text_action1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:text="Share"
android:showAsAction="ifRoom"
android:textSize="12dp"
android:textColor="#color/gen_black"
android:gravity="left"
android:actionProviderClass=
"android.widget.ShareActionProvider"/>
</LinearLayout>
<View android:layout_width="#dimen/view_width_small"
android:layout_height="match_parent"
android:background="#color/grey_light"/>
<LinearLayout android:id="#+id/layout_action2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_filter_none_black_18dp"/>
<TextView android:id="#+id/text_action2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:text="Similar"
android:textSize="12dp"
android:textColor="#color/gen_black"
android:gravity="left"/>
</LinearLayout>
<View android:layout_width="#dimen/view_width_small"
android:layout_height="match_parent"
android:background="#color/grey_light"/>
<LinearLayout android:id="#+id/layout_action3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_favorite_border_black_18dp"/>
<TextView android:id="#+id/text_action3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_marginLeft="8dp"
android:text="Store Locator"
android:textSize="12dp"
android:textColor="#color/gen_black"
android:gravity="left"/>
</LinearLayout>
</LinearLayout>
<View android:layout_width="match_parent"
android:layout_height="#dimen/view_width_small"
android:background="#color/grey_light"
android:layout_marginTop="8dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Details"
android:textSize="16dp"
android:textColor="#color/gen_black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="\u2022 Regular fit, full sleeve"
android:textSize="12dp"
android:textColor="#color/gen_black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="\u2022 Fabric: Cotton"
android:textSize="12dp"
android:textColor="#color/gen_black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="\u2022 Pattern: printed"
android:textSize="12dp"
android:textColor="#color/gen_black"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="horizontal"
android:weightSum="2"
android:elevation="30dp"
android:background="#color/gen_black">
<TextView android:id="#+id/text_action_bottom1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/gen_white"
android:text="ADD TO CART"
android:textSize="14dp"
android:textColor="#color/gen_black"
android:textStyle="bold"
android:gravity="center"/>
<TextView android:id="#+id/text_action_bottom2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#4dc3ff"
android:text="BUY NOW"
android:textSize="14dp"
android:textColor="#color/gen_white"
android:textStyle="bold"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
Main.xml (In this xml i use the menu item which show in navigation drawer bar)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_search"
android:title="#string/action_search"
android:icon="#drawable/ic_search_white_24dp"
app:showAsAction="collapseActionView|ifRoom"
app:actionViewClass="android.support.v7.widget.SearchView"/>
<item android:id="#+id/action_notifications"
android:title="#string/action_notifications"
app:showAsAction="always"
android:icon="#drawable/ic_notifications_white_24dp"/>
<item android:id="#+id/action_cart"
android:title="#string/action_cart"
app:showAsAction="always"
android:icon="#drawable/ic_menu_notifications"/>
</menu>
Please Override this Method in your ItemDetailsActivity to Show Menu
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
verride this Method in your ItemDetailsActivity to Handle Click Events
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_cart:
dosomething();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
I have six RadioButtons belonging to the same question, and I need to put them in some RadioGroup. But these RadioButtons is in some LinearLayouts. I tried to put one RadioGroup to each RadioButton, but i don't know what i need to do for it to work.
tab_layout_a.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<RadioButton
android:id="#+id/tipoPackRadio1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="Normal"
android:textSize="#dimen/radiobuttons_font_sz" />
<RadioButton
android:id="#+id/tipoPackRadio2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text="Gilda"
android:textSize="#dimen/radiobuttons_font_sz" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="0.9"
android:orientation="horizontal">
<RadioButton
android:id="#+id/tipoPackRadio3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="0dp"
android:layout_weight="1"
android:text="Aged Pack \n(cheese/salve)"
android:textSize="#dimen/radiobuttons_font_sz" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="1"
android:orientation="horizontal">
<RadioButton
android:id="#+id/tipoPackRadio4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="0dp"
android:layout_weight="1"
android:text="Fellowship"
android:textSize="#dimen/radiobuttons_font_sz" />
<RadioButton
android:id="#+id/tipoPackRadio5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text="Fertilizer"
android:textSize="#dimen/radiobuttons_font_sz" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.9"
android:orientation="horizontal">
<RadioButton
android:id="#+id/tipoPackRadio6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="0dp"
android:layout_weight="1"
android:text="Aged Pack \n(honey)"
android:textSize="#dimen/radiobuttons_font_sz"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Try this solution..
class MyActivity extends Activity {
RadioButton _Rone, _Rtwo, _Rthree;
#Override
protected void onCreate(Bundle savedInstanceState) {
//after setContentView(.....)
_Rone = (RadioButton) findViewById(R.id.radio_one);
_Rtwo = (RadioButton) findViewById(R.id.radio_two);
_Rthree = (RadioButton) findViewById(R.id.radio_three);
_Rone.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
_Rone.setChecked(true);
_Rtwo.setChecked(false);
_Rthree.setChecked(false);
}
});
_Rtwo.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
_Rone.setChecked(false);
_Rtwo.setChecked(true);
_Rthree.setChecked(false);
}
});
_Rthree.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
_Rone.setChecked(false);
_Rtwo.setChecked(false);
_Rthree.setChecked(true);
}
});
// do code here
}`
by clicking on anyradio button the other's selection will reset.
I have a big issues about onSwiped method and set a button's visibility to VISIBLE. Here my code Java Class :
#Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
mRecyclerView.getAdapter();
StepListAdapter.ViewHolder listViewHolder = (StepListAdapter.ViewHolder) viewHolder;
listViewHolder.itemView.setBackgroundColor(mContext.getResources().getColor(R.color.accent));
listViewHolder.titleView.setVisibility(View.GONE);
listViewHolder.locationView.setVisibility(View.GONE);
listViewHolder.status.setVisibility(View.GONE);
listViewHolder.undoButton.setVisibility(View.VISIBLE);
listViewHolder.undoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Do something
}
});
}
And here my xml layout file:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_marginRight="5sp"
android:clickable="true"
android:foreground="?selectableItemBackground"
card_view:cardCornerRadius="1sp"
card_view:cardElevation="2sp"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="5sp">
<RelativeLayout
android:background="#color/cardview_light_background"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/title_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:singleLine="true"
android:ellipsize="end"
android:layout_gravity="center"
android:padding="5sp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="#string/empty"/>
<TextView
android:id="#+id/location_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:ellipsize="end"
android:layout_gravity="center"
android:padding="5sp"
android:textColor="#color/dark_grey"
android:layout_below="#id/step_title_text"
android:text="#string/empty"/>
<ImageView
android:id="#+id/status_image"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"/>
<Button
android:id="#+id/undo_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/undo"
android:textAllCaps="true"
android:visibility="gone"
android:textColor="#android:color/white"
android:layout_gravity="end|center_vertical"
android:layout_alignParentRight="true"
style="#style/Base.Widget.AppCompat.Button.Borderless"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
My problem is that when the method onSwiped was called, and after I setup the VISIBILITY of the button by Java code, the main card doesn't show the button .
Thanks a lot guys
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
}